Connect to MySQL MySQL database from localhost

I am trying to connect to my MySQL database on my online server through PHP on my localhost.

$con = mysql_connect("$hostname", "$username", "$password");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db($databasename, $con);

When I upload the script to the server, it connects to the database perfectly. However, when I load the script on my localhost, it will not connect to the online database. I disabled my firewall to make sure it is not blocking it.

Is this connection correctly formatted correctly? Any other suggestions?

+5
source share
5 answers

Your MySQL server must have your IP address (or %as a wild card) specified on the allowed hosts.

+7
source

? .

+2

, ( IP). user mysql. ( ), .

+2

.

, MySQL . , , , .

If you have not configured your server yourself, you will probably have to talk with your hoster's user support, because they have permission to change the settings and more accurate information on this topic.

+2
source

It's time to switch to mysqli_*orPDO

Documentation

0
source

All Articles