0

Hi, i just hosted my website on 000webhost for free and somehow i cant connect with my database resulting to that i cant login on my website. How can i solve that? Please help. thank you

Heres my code for db connection

'<?php

$db_host="mysql1.000webhost.com";
$db_username="a1924971_user";
$db_password="*************";
$db = "a1924971_learn";

$cn = mysqli_connect($db_host,$db_username,$db_password,$db);


if(!$cn){
    die(mysqli_connect_error());
}

?> '

4
Contributors
4
Replies
18
Views
1 Year
Discussion Span
Last Post by OtepTheThird
0

Does the error message provide useful information? If you have another way of accessing the database, control panel or ssh, etc, you can test out connecting via those means.
But the basics you have there look right from a code perspective so the problem might lie in the username/password or configuration that your host hasn't set up right.

0

I highly doubt that your free host has database in the same server. In other words, $db_host="mysql1.000webhost.com"; is very likely to be wrong. You need to find out what you really need to connect to from your host. Normally, they would have it as an IP address, not a DNS...

Edited by Taywin

0

Dont use mysql as it was deprecated, use mysqli or PDO try this..

 <?php 
    try{
    $db_host="mysql1.000webhost.com";// change to localhost or servername
    $db_username="a1924971_user";
    $db_password="*************";
    $db = "a1924971_learn";
    $cn = new PDO("mysql:host=$db_host;dbname=$db",$db_username,$db_password);
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }catch(PDOException $e){
        echo $e->getMessage();
    }
 ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.