php - MySQL connection error -


i trying execute following php script (called test1.php, say) on web server running apache. script tries connect mysql server:

===============================================

$myhost = "localhost";  $myuser = "anyone";  $mypwd = "1234";  $link = mysql_connect($myhost,$myuser,$mypwd);  if (!$link) {  die(mysql_errno().": ".mysql_error()."\n");  }  echo "connected successfully.\n"; 

================================================

i kept receiving errors this:

2002: can't connect local mysql server through socket '/var/lib/mysql/mysql.sock' (13)

however, root or normal user, can execute above script shell:

shell>php /var/www/html/test1.php

connected successfully.

i confused , grateful if has hints problem. much.

execute <?php phpinfo(); both under apache , cli , compare mysql.default_socket value.

after valid socket path (from cli phpinfo) - can specify same php.ini, or right in code:

$link = mysql_connect($myhost . ':/tmp/mysql.sock', $myuser, $mypwd); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -