Mysql_real_escape_string () Failed to set server link

I get this error when I try to use mysql_real_escape_string ().

Access denied for user 'ODBC'@'localhost' (using password: NO) 

I do not understand why I should be connected to the database in order to check if the values ​​to insert into MySQL match.

+3
source share
3 answers

This is because mysql_real_escape_string takes into account the current connection character set. So he needs a connection. :-)

If you do not want to manually configure the connection in advance, you can set various MySQL runtime values in your .ini file.

However, if you use your own database class (or just manual commands), it is often worthwhile to establish a connection throughout the life of your script.

+11
source

Since escaping depends on the character set on the server. See mysql_real_escape_string in the MySQL manual (a PHP function of the same name is just a wrapper around this C function).

+1
source

find and delete

 mysql_close(); 

this function is completely disconnected from the MySQL server

-3
source

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


All Articles