Mysqli:未知的服务器主机
看起来这是一个很常见的错误,但我无法解决。我正在运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题在于 MySQLi 不接受端口作为主机名的一部分,而是作为单独的参数。所以我认为这就是你应该如何打开连接的方式:
或者也许根本不提供端口,因为 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:
Or perhaps, do not give the port at all because 3306 is the default one.
检查数据库上您的用户(“myUser”)的权限。确保权限允许通过“%”(或仅您的 IP)进行连接,而不仅仅是“localhost”(127.0.0.1)。然后确保“重新加载权限”。
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'.
mysqli找不到数据库服务器,需要检查域和端口号是否正确
mysqli cannot find the database server, you need to check that domain and port number are correct