Mysqli:未知的服务器主机

发布于 2024-11-17 03:35:22 字数 768 浏览 1 评论 0原文

看起来这是一个很常见的错误,但我无法解决。我正在运行 PHP 5.3.1 外部 MySQL 服务器 5.5.8 - 均随 Phpmyadmin 安装并运行 Windows Server 2k8R2。

当我尝试以下操作时:

   $connection = new mysqli("myhost.com:3306", "myUser", "myPwd", "myDB");
   $result = $connection->prepare("SELECT * FROM tt_staff
                           WHERE crew_type = ?
                           AND inaktiv_vakt = 0
                           ORDER BY ansvarlig_vakt DESC, crew_type, navn_vakt");
   $result->bind_param("s", $value);
   $result->execute();
   $result->bind_result($value, $name);

我得到“ 警告:mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): 未知的 MySQL 服务器主机 (...)"

我确保在 DB 服务器上的 php.ini 中启用了 Mysqli,但是这也是我所做的一切,因为我被告知这应该是开箱即用的,因为这是我第一次使用准备好的语句,很可能在某个地方有一个简单的拼写错误。 。

Seems like this is a pretty common error, but I can't work it out. I'm running PHP 5.3.1 towards an
external MySQL server 5.5.8 - both installed with Phpmyadmin and running Windows Server 2k8R2.

When I try the following:

   $connection = new mysqli("myhost.com:3306", "myUser", "myPwd", "myDB");
   $result = $connection->prepare("SELECT * FROM tt_staff
                           WHERE crew_type = ?
                           AND inaktiv_vakt = 0
                           ORDER BY ansvarlig_vakt DESC, crew_type, navn_vakt");
   $result->bind_param("s", $value);
   $result->execute();
   $result->bind_result($value, $name);

I get the "
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host (...)"

I made sure that the Mysqli is enabled in the php.ini on the DB-server, but that's also all I've done as I've been told this should work out-of-the-box. Since this is the first time I'm working with prepared statements there very well might be a simple typo error in there some place.

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

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

发布评论

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

评论(3

江湖正好 2024-11-24 03:35:22

问题在于 MySQLi 不接受端口作为主机名的一部分,而是作为单独的参数。所以我认为这就是你应该如何打开连接的方式:

$connection = new mysqli("myhost.com", "myUser", "myPwd", "myDB", "3306");

或者也许根本不提供端口,因为 3306 是默认端口。

The problem is that MySQLi does not accept the port as part of the hostname but as a separate parameter. So I think this is how you should open your connection:

$connection = new mysqli("myhost.com", "myUser", "myPwd", "myDB", "3306");

Or perhaps, do not give the port at all because 3306 is the default one.

回忆凄美了谁 2024-11-24 03:35:22

检查数据库上您的用户(“myUser”)的权限。确保权限允许通过“%”(或仅您的 IP)进行连接,而不仅仅是“localhost”(127.0.0.1)。然后确保“重新加载权限”。

Blockquote注意:phpMyAdmin直接从MySQL的权限表获取用户的权限。如果这些表的内容已被手动更改,则它们可能与服务器使用的权限不同。在这种情况下,您应该在继续之前重新加载权限。

Check the Privileges for your user ('myUser') on the Database. Make sure the privileges allow connections thru '%' (or just your IP), not just 'localhost' (127.0.0.1). Then make sure to "reload priviliges'.

BlockquoteNote: phpMyAdmin gets the users' privileges directly from MySQL's privilege tables. The content of these tables may differ from the privileges the server uses, if they have been changed manually. In this case, you should reload the privileges before you continue.

檐上三寸雪 2024-11-24 03:35:22

mysqli找不到数据库服务器,需要检查域和端口号是否正确

mysqli cannot find the database server, you need to check that domain and port number are correct

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