如何从本地计算机访问cPanel数据库

时间:2019-03-23 20:38:20

标签: php mysql pdo cpanel

我试图从我的计算机访问cPanel数据库,我已经将我的IP地址添加到了远程MySQL访问主机,但是它一直抛出错误

Connection failed: SQLSTATE[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. 

这是我的代码:

try {
    $conn = new PDO("mysql:host=$servername;dbname=myDB;port=3306", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
}
catch(PDOException $e)
{
    echo "Connection failed: " . $e->getMessage();
}

0 个答案:

没有答案