我正在尝试通过PHP中的MySQLi将数据插入MariaDB。 MariaDB和Apache都在同一台计算机上。从上一页提取HTML变量后,我的代码尝试在本地连接到MariaDB,然后执行错误检查。不幸的是,MySQLi没有连接,并且我收到一条错误消息。
我在Windows 8.1上使用开发WAMPserver。我在MySQLi构造函数参数(而不是localhost)中尝试了127.0.0.1,并禁用了防火墙。它没有帮助。
// Connect to database
$db = new mysqli('localhost', 'user', 'password', 'database');
if ($db->connect_errno)
{
echo 'Error '.$db->connect_errno.$db->connect_error.'. Could not connect to database. Please try again later.';
exit;
}
这是WAMP的本地安装,并且MariaDB凭据正确。不过,我仍然收到此错误:
( ! ) Warning: mysqli::__construct(): (HY000/2002): No connection could be
made because the target machine actively refused it. in
C:\wamp64\www\mysite\createaccount.php on line 30
Call Stack
# Time Memory Function Location
1 0.0002 410248 {main}( ) ...\createaccount.php:0
2 0.0003 410632 __construct ( ) ...\createaccount.php:30
Error 2002No connection could be made because the target machine actively
refused it. . Could not connect to database. Please try again later.