Troubleshooting "Cannot connect to local MySQL server via socket" when mysql_real_escape_string () is called

I get an error message:

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

Why am I getting this error? Does Mysql_real_escape_string () work on all my pages except one? This is because MySQL is on a different server on the PHP server - if so, how can I fix it?

$fname = $_POST['fname'];
$fname = stripslashes($fname);
$fname = mysql_real_escape_string($fname);
+3
source share
1 answer

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

mysql_real_escape_string(), PHP . , mysql_connect().

+9

Source: https://habr.com/ru/post/1737949/


All Articles