开发者

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

开发者 https://www.devze.com 2022-12-23 21:56 出处:网络
This question already has answers here: Can't connect to local MySQL server through socket (2 answers)
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

精彩评论

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