目前的項目開發完了一部分,本地測試正常,但是放到伺服器上就不行了。
本地環境:xampp-3.2.2(php-5.6.15, apache-2.4.17)
伺服器環境:php-5.3.3、nginx-1.0.15、php-fpm
我嘗試了3種連接配接mysql的方法,在本地無一失敗,在伺服器無一成功。。
PDO方法
代碼:
$dsn = "mysql:dbname=$db;port=$this->dbPort;host=$this->dbHost;charset=$charset";
try {
$this->conn = new PDO($dsn, $this->dbUser, $this->dbPasswd);
return $this->conn;
} catch (PDOException $e) {
$this->DealError($e);
return false;
}
因為伺服器的php版本太舊,無法使用PDO通路自定義的端口,于是放棄。
mysql方法和mysqli方法
代碼:
//mysql
$this->conn = mysql_connect($this->dbHost.":".$this->dbPort, $this->dbUser, $this->dbPasword);
//mysqli
$this->[email protected]_connect($this->dbHost, $this->dbUser, $this->dbPasswd, $this->dbName. $this->dbPort);
這個兩個方法都會會提示如下錯誤:
Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)
很明顯并沒有去連接配接伺服器的自定義端口,但調用時确實指定了自定義端口,不知道這是什麼原因