您好我正在尝试使用PHP访问远程数据库。 远程数据库是MySQL。下面是我得到的错误的屏幕截图。任何人都可以帮助我。提前谢谢。
以下是我检查完全没问题的: -
这是数据库连接代码
<?php
class Database {
/*
public $dbhost = "mysql:dbname=a_t;host=localhost:3306";
$dbhost = "mysql:host=10.75.225.171;port=3306;dbname=apt";
public $dbuser = "root";
public $dbpass = "root";
public $dbname = "a_t";
public $connection;
public $selectdb;
public $isConnected;
public $dbh;
*/
public $dbhost = "mysql:dbname=25thcraft;host=52.xx.xx.xxx;port=3306";
public $dbuser = "tribhuvan";
public $dbpass = "123456";
public $dbname = "25thcraft";
public $connection;
public $selectdb;
public $isConnected;
public $dbh;
//$user = 'dbuser';
//$password = 'dbpass';
public function Connection()
{
try
{
$this->dbh = new PDO($this->dbhost, $this->dbuser, $this->dbpass);
// echo "true";
return $this->dbh;
}
catch(Exception $e)
{
$this->isConnected = false;
throw new Exception($e->getMessage());
}
}
public function Disconnect()
{
$this->datab = null;
$this->isConnected = false;
}
}
?>
答案 0 :(得分:0)
如果要建立与远程连接的连接,则必须将主机配置为接受这些连接。默认禁用哪些。最好的,您可以联系主持人来研究这个。