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


$db = "a1924971_learn";

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


?> '

Recommended Answers

All 4 Replies

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.

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...

Can you go to your 000webhost cpanel and look for servername on the right panel..

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

    $db_host="mysql1.000webhost.com";// change to localhost or servername
    $db = "a1924971_learn";
    $cn = new PDO("mysql:host=$db_host;dbname=$db",$db_username,$db_password);
    }catch(PDOException $e){
        echo $e->getMessage();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.