Mysql_real_escape_string()无法建立到服务器的链接 [英] Mysql_real_escape_string() A link to the server could not be established
问题描述
当我尝试使用mysql_real_escape_string()时出现此错误.
I get this error when I try to use mysql_real_escape_string().
Access denied for user 'ODBC'@'localhost' (using password: NO)
我不明白为什么我必须连接到数据库以检查这些值是否可以插入MySQL.
I don't understand why I must be connected to the database to check if the values are OK to insert to MySQL.
推荐答案
这是因为 mysql_real_escape_string 考虑了当前字符集连接的.因此,它需要一个连接. :-)
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.
这篇关于Mysql_real_escape_string()无法建立到服务器的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!