When attempting to connect using PHP to a MySQL database I get the following error:
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/username/public_html/index.php on line 7
Couldn't connect to server.
I am able to telnet into MySQL using the same username and password with no problem.
PHP and MySQL are on the same server, I do not have root priv.
Here is the code I am using, I will alter this to use an include file once I get it working:
<?
$dbhost = 'localhost';
$dbusername = 'username'; //username
$dbpasswd = 'password'; //password
$database_name = 'db'; //database
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection) or die("Couldn't select database.");
?>
Obviously I have changed the username password and db for security reasons to post the code.