Christophe Harris Christophe Harris - 2 months ago 5x
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';


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
so I imagine the databasename should be working. Thanks for any help.


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.