php串連mysql識別不到連接埠號碼

來源:互聯網
上載者:User
目前的項目開發完了一部分,本地測試正常,但是放到伺服器上就不行了。
本地環境: xampp-3.2.2(php-5.6.15, apache-2.4.17)
伺服器環境: php-5.3.3nginx-1.0.15php-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->conn=@mysqli_connect($this->dbHost, $this->dbUser, $this->dbPasswd, $this->dbName. $this->dbPort);

這個兩個方法都會會提示如下錯誤:

Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)

很明顯並沒有去串連伺服器的自訂連接埠,但調用時確實指定了自訂連接埠,不知道這是什麼原因

回複內容:

目前的項目開發完了一部分,本地測試正常,但是放到伺服器上就不行了。
本地環境:xampp-3.2.2(php-5.6.15, apache-2.4.17)
伺服器環境:php-5.3.3nginx-1.0.15php-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->conn=@mysqli_connect($this->dbHost, $this->dbUser, $this->dbPasswd, $this->dbName. $this->dbPort);

這個兩個方法都會會提示如下錯誤:

Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)

很明顯並沒有去串連伺服器的自訂連接埠,但調用時確實指定了自訂連接埠,不知道這是什麼原因

伺服器的mysql開啟遠端存取先。
建議還是先使用mysqlworkbench測試一下,確定ok,再上服務端程式。

1、確定是否許可權是有的,根據網上尋找的資訊:mysql 13 的錯誤是提示有寫入權限的問題
2、mysql 是否自訂的連接埠上進行監聽
3、mysql伺服器是否配置了可以遠端連線

根據題主描述,很像mysql沒有開啟外連,
telnet cins.swpu.edu.cn 連接埠號碼,試一下看看什麼反饋。或者你直接在伺服器上查看mysql user表你的使用者資訊。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.