mysql_real_escape_string() 无法建立到服务器的链接
当我尝试使用 mysql_real_escape_string() 时出现此错误。
Access denied for user 'ODBC'@'localhost' (using password: NO)
我不明白为什么我必须连接到数据库来检查这些值是否可以插入到 MySQL。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为 mysql_real_escape_string 考虑了连接的当前字符集。因此,它需要连接。 :-)
如果您不想提前手动设置连接,您可以设置各种MySQL 运行时默认值 在 .ini 文件中。
但是,如果您使用自己的数据库类(或只是手动命令),通常值得在脚本生命周期的早期建立连接。
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 手册中的 mysql_real_escape_string (同名的 PHP 函数只是此 C 函数的包装器)。
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).
找到并删除
这个函数,完全断开与MySQL服务器的连接
find and delete
this function disconnect completely from MySQL server