gpt4 book ai didi

php - "Connection Refused"或 "No Such File or Directory"

转载 作者:行者123 更新时间:2023-11-29 17:42:52 25 4
gpt4 key购买 nike

我有一个website由 DreamHost 主办。子域“fakestore”有一个数据库,因此有一个访问该数据库的脚本。但是,我无法使该数据库正常工作。我尝试将 $servername 更改为 127.0.0.1aashishbharadwaj.com。如果我使用 localhost,则会收到错误It no work!SQLSTATE[HY000] [2002] No such file or directory。如果我使用其他两个,我会得到它不起作用!SQLSTATE[HY000] [2002]连接被拒绝

<?php
$servername = 'localhost'; //I've tried numerous things here, with different errors

//For my server
$username = "username"; //Not actual username
$password = "password"; //Not actual password

$dbname = 'database_name'; //Not actual database name

try {
$db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
} catch (PDOException $e) {
$error_message = $e->getMessage();
echo "It no work!";
echo $error_message;
exit();
}
?>

最佳答案

建议您检查创建数据库时创建的主机名,根据https://help.dreamhost.com/hc/en-us/articles/215733647-What-PHP-commands-do-I-use-to-connect-to-my-database-

如果您想使用localhost - 请阅读https://stackoverflow.com/a/1819767/5920627

关于php - "Connection Refused"或 "No Such File or Directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49928226/

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