Christophe Harris Christophe Harris - 3 months ago 6
MySQL Question

mysqli_connect not working

In my PHP script I have :

$con = mysqli_connect("12.345.67.89", "root", "password", "databasename");

if ($con) {
echo 'connected';
} else {
echo 'not connected';
}

etc....etc....


When I open 12.345.67.89/Register.php in my browser I get :

not connected


root, password and databasename are all correct. 12.345.67.89 is my IP address. Should I be putting something else in there? Is it the location of my actual mysql database I should be putting in there or just my digitalocean IP address?

I can access phpmyadmin by simply going to
12.345.67.89/phpmyadmin/
so I imagine the databasename should be working. Thanks for any help.

Answer

try this $con = mysqli_connect("localhost", "root", "password", "databasename"); added "localhost"

As mentioned above in comment

if you want to use your public ip then you need to open mysql running port in your firewall. try lan ip or localhost as host name

So, please take a note on that.