CHarris
CHarris

Reputation: 2793

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.

Upvotes: 0

Views: 5756

Answers (1)

Mittul Chauhan
Mittul Chauhan

Reputation: 417

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.

Upvotes: 2

Related Questions