PHP 中 mysql_connect 的奇怪行为

发布于 2024-12-11 11:08:13 字数 415 浏览 4 评论 0原文

这就是在本地主机上创建到 MySQL 服务器的连接的方式

$Connection = mysql_connect("localhost","root","");

,但 MySQL 似乎忽略了我的用户名和密码,即使我使用一些无意义的用户名和密码创建连接。密码:

$Connection = mysql_connect("localhost","nonsense-username","");

这两种情况都给我 $Connection 作为“资源(39)类型(mysql 链接)”。只有当密码为空时才会发生这种情况。当密码为空时,MySQL 是否接受任何用户名的默认行为?

但当给出这样的“废话用户名”时,$Connection 应该等于“false”。有什么问题吗?

This is how a connection is created to MySQL server at localhost

$Connection = mysql_connect("localhost","root","");

But MySQL seems ignoring my username and password, even if I create the connection with some nonsense username & password:

$Connection = mysql_connect("localhost","nonsense-username","");

Both cases give me the $Connection as "resource(39) of type (mysql link)". And this only happens when password is blank. Is it a default behaviour of MySQL to accept any username when password is blank?

But it is supposed to have $Connection equal 'false' when such 'nonsense-username' given. Anything wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单挑你×的.吻 2024-12-18 11:08:13

我假设您已经在自己的计算机上设置了 MySQL 服务器,而没有配置用户、权限或类似的东西。如果是这种情况,则原因可能是 SQL 安全模式。如果在 php.ini 文件中,sql.safe_mode 设置为 1,则 PHP 会将您传递给 mysql_connect() 的任何参数替换为其默认值。这肯定可以解释这种行为。尝试查看 phpinfo() 看看是否是这种情况。

I'm going to assume that you've setup the MySQL server on your own computer, without configuring users, permissions or things like that. If that's the case, then the cause might be SQL Safe Mode. If in your php.ini file, sql.safe_mode is set to 1, then PHP will substitute any arguments you pass to mysql_connect() with their defaults. That would certainly explain this behavior. Try looking at phpinfo() to see if that's the case.

装迷糊 2024-12-18 11:08:13

看来您在安装 php-mysql 后没有重新启动网络服务器。请重新启动网络服务器,它应该可以工作。
我花了两个小时调试,简单的解决方案是重新启动

It seems you have not restarted the webserver after install of php-mysql. Please restart the webserver it should work.
I spent two hours debugging that and the simple solution was restart

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文