函数Mysql-connect错误

时间:2012-12-26 07:01:35

标签: php mysql

我在connection.php文件上有问题,该文件在localhost上运行正常,但上传到托管时出现如下错误:

Warning: mysql_connect () [function.mysql-connect]: Can not connect to local MySQL server through socket '/ var / lib / mysql / mysql.sock' (2) in / home/content/84/10207284/html / koneksi.php on line 6

我的脚本是这样的:

<? php
    $server = "localhost";
    $username = "*******";
    $password = "******";
    $database = "*****";
    mysql_connect ("$server", "$username", "$password") or die ("Failed");/ /  the error Line
    mysql_select_db ("holidayhappy") or die ("Database not found");
?>

我尝试使用服务器IP安全端口更改localhost,但它也不能正常工作。

有人可以帮我解决这个问题......?

1 个答案:

答案 0 :(得分:0)

如果您正在使用服务器托管,并且mysql服务器安装在同一主机上

然后尝试将servername作为localhost

如果没有,请确保启用远程访问

按照下面提到的链接

中的教程

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html