gpt4 book ai didi

php - 连接到 MySQL 时出现 PDO 错误

转载 作者:行者123 更新时间:2023-11-29 04:49:04 28 4
gpt4 key购买 nike

<分区>

我正在尝试连接到存储在本地主机上的 MySQL 数据库。

代码:

$config['db'] = array( 
'host' => 'localhost',
'username' => 'root',
'password' => 'mypass',
'dbname' => "dbname"
);

echo $config['db']['host'];

try {
$conn = new PDO('mysql:host=127.0.0.1;dbname=sfrtv', 'root', 'usbw', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}

此代码返回以下错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (10061)' in H:\path\filename.php:12 Stack trace: #0 H:\path\filename.php(12): PDO->__construct('mysql:host=loc....', 'root', 'mypass') #1 {main} thrown in H:\path\filename.php(12) on line 12

关于如何纠正这个问题有什么建议吗?

谢谢!

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com