我想问你,如何使用PDO通过隧道连接到外部数据库?
我的数据库类是:
<?php
class Database {
//Server Params
private $server_addres = 'xx.xx.xx';
private $port = '222';
private $user = 'myuser';
private $pass = 'mypass';
//DB Params
private $host = '127.0.0.1';
private $db_name = 'mydbname';
private $username = 'mydbuser';
private $password = 'mydbpassowrd';
private $conn;
//DB Connect
public function connect() {
$this->conn = null;
try {
//???
shell_exec();
$this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db_name, $this->username, $this->passowrd);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch( PDOException $e ) {
echo 'Connection Error: ' . $e->getMessage();
}
return $this->conn;
}
}
我应该使用shell_exec()函数吗,如果可以,怎么办?
谢谢您的帮助!