Mysql_real_escape_string()无法建立到服务器的链接 [英] Mysql_real_escape_string() A link to the server could not be established

查看:127
本文介绍了Mysql_real_escape_string()无法建立到服务器的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆