我正在尝试连接到我的数据库,但当我使用 127.0.0.1 而不是 localhost 时出现错误。
Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
如果我使用 localhost 而不是 127.0.0.1 它工作正常。有人对此有任何见解吗?
用于连接的代码是
<?php
$db = new mysqli('127.0.0.1', 'root', '', 'dbname');
?>