-->

Mysql_real_escape_string() A link to the server co

2019-02-24 19:37发布

问题:

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

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

I don't understand why I must be connected to the database to check if the values are OK to insert to MySQL.

回答1:

This is because mysql_real_escape_string takes into account the current character set of the connection. As such, it needs a connection. :-)

If you don't want to manually set up a connection in advance, you could set the various MySQL runtime defaults within your .ini file.

However, if you're using your own database class (or simply the manual commands), it's often worth establishing the connection early in the lifetime of your script.



回答2:

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



回答3:

find and delete

mysql_close();

this function disconnect completely from MySQL server