Troubleshooting "Can't connect to local MySQL server through socket" when calling mysql_real_escape_string() [duplicate]
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()
.
精彩评论