开发者

Troubleshooting "Can't connect to local MySQL server through socket" when calling mysql_real_escape_string() [duplicate]

This question already has answers here: Can't connect to local MySQL server through socket (2 answers) Closed 9 years ago.

I am getting the error:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Why do I get this error? The mysql_real_escape_string() works on all of my pages apart from one? 开发者_Python百科Is it something to do with MySQL being on a different server to the PHP server - if so, how do I fix it?

$fname = $_POST['fname'];
$fname = stripslashes($fname);
$fname = mysql_real_escape_string($fname);


This is because you never call mysql_connect() before the use of mysql_real_escape_string().

In order to use mysql_real_escape_string(), PHP must be connected to the database. In order to connect to the database, you must use mysql_connect().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜