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.

3条回答
来,给爷笑一个
2楼-- · 2019-02-24 20:02

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.

查看更多
放荡不羁爱自由
3楼-- · 2019-02-24 20:12

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).

查看更多
干净又极端
4楼-- · 2019-02-24 20:15

find and delete

mysql_close();

this function disconnect completely from MySQL server

查看更多
登录 后发表回答