i've mysql database over cpanel, i wish 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);
?>

After i run it, it can't connect with mysql database over cpanel. and that i even attempted up

$con1 = mysql_connect("mywebsiteip:portnumber","mysql_username","mysql_user_password");

Can any tell me, which is nice way. Below may be the image or error enter image description here

Warning: mysql_connect() [function.mysql-connect]: 
php_network_getaddresses: getaddrinfo failed: No such host is known 

This error messages indicates that localhost can not be resolved, and so the "client" (your php script) does not know where you can send the connect request to.

Either look at your DNS configurations or make use of an IP adress rather, where your MySQL server is obtainable.

You need to provide the correct connection code!

$con1 = mysql_connect("localhost:/tmp/mysql.sock","mysql_username","mysql_user_password");

I really hope this will / must meet your needs. Enjoy!

Great work! yeah, we all like free!

in case your attempting to connect remote ip

  1. Mysql server have to accept remote connection
  2. Mysql user must have remote access previlage

if you do not have 1 of these it will not work.

Automatically, cPanel-installed mysql databases only allow connections in the localhost (ie the server cpanel/mysql is a component of). To include other hosts, sign in to cPanel and visit 'Remote Database Access Hosts' (this might be known as something slightly different based on version).

You can include your Ip, hostname or % to permit connections from the computer. However, indicating % is really a large security risk, so utilize it with caution.

FYI, this really goes on webmasters.stackexchange.com, because it involves administration a lot more than programming.