Reputation: 4078
i have mysql database over cpanel, i want to access through my localhost page..
<?php
$con1 = mysql_connect("mywebsiteip","mysql_username","mysql_user_password");
if(!$con1)
{
die ("Could not connect " . mysql_error());
}
else
{
echo "Good connection";
}
mysql_close($con1);
?>
When i run it, it cannot connect to mysql database over cpanel. and i even tried up
$con1 = mysql_connect("mywebsiteip:portnumber","mysql_username","mysql_user_password");
Can any let me know, which one is good way. Below is the image or error
Upvotes: 2
Views: 15643
Reputation: 766
You should give the correct connection code!
$con1 = mysql_connect("localhost:/tmp/mysql.sock","mysql_username","mysql_user_password");
I hope this should / must work for you. Enjoy!
Upvotes: 1
Reputation: 16314
Warning: mysql_connect() [function.mysql-connect]:
php_network_getaddresses: getaddrinfo failed: No such host is known
This error messages suggests that localhost
can't be resolved, therefore the "client" (your php script) doesn't know where to send the connect request to.
Either check your DNS settings or use an IP adress instead, where your MySQL server is accessible.
Upvotes: 1
Reputation: 2277
if your trying to connect remote ip
if you dont have 1 of them it wont work.
Upvotes: 0
Reputation: 28793
By default, cPanel-installed mysql databases only allow connections from the localhost (ie the server cpanel/mysql is installed on). To add other hosts, log in to cPanel and go to 'Remote Database Access Hosts' (this may be called something slightly different depending on version).
You can add your IP address, hostname or %
to allow connections from any computer. However, specifying %
is a big security risk, so use it with caution.
FYI, this question really belongs on webmasters.stackexchange.com, as it involves administration more than programming.
Upvotes: 2