当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - trying to access remote database using php

问题描述:

Hi i am trying to access remote database using PHP.

remote database is MySQL. Below is the screen shot of the error i am getting.can any one help me.Thanks in advance.

following are perfectly alright i have checked:-

  1. Database name
  2. port number
  3. IP address
  4. username and password

here is the database connectivity code

<?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;

}

}

?>

网友答案:

If you want make a connection to a remote connection, the host must be configured to accept these connections. Which are disables by default. The best you can contact the host to look into this.

分享给朋友:
您可能感兴趣的文章:
随机阅读: