Mysql_real_escape_string() A link to the server could not be established

女生的网名这么多〃 提交于 2019-12-04 04:13:28

问题


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



来源:https://stackoverflow.com/questions/4574665/mysql-real-escape-string-a-link-to-the-server-could-not-be-established

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!