【发布时间】:2018-09-30 09:06:00
【问题描述】:
我有一个由 DreamHost 托管的website。子域“fakestore”有一个数据库,因此有一个访问该数据库的脚本。但是,我无法使该数据库正常工作。我尝试将$servername 更改为127.0.0.1 和aashishbharadwaj.com。如果我使用 localhost,我会收到错误 It no work!SQLSTATE[HY000] [2002] No such file or directory。如果我使用其他两个,我会得到It no work!SQLSTATE[HY000] [2002] Connection refused。
<?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();
}
?>
【问题讨论】:
-
在 DreamHost 上
-
我花了大约 4 个小时在谷歌上搜索并尝试排除故障。请不要做任何假设。
-
在我看来“它不起作用!”会更正确
-
@kay27 那是在开玩笑...
-
@Nic3500 请阅读帖子,我确实发布了我尝试过的内容、失败的原因以及错误。具体来说,我尝试了另外两个主机名,一个提供了不同的错误。
标签: php mysql server dreamhost