2017-04-26 112 views
0

在我安裝了我的應用程序並正常工作之前,當我在其他設備上使用相同的代碼和配置進行新安裝時, 我在嘗試連接隧道mysql與pdo擴展時出現錯誤yii 1PHP PDO MySQL隧道連接雙端口

這樣的錯誤消息:

CDbConnection未能打開數據庫連接:SQLSTATE [HY000] [2002]無法解析地址 「本地主機:3307:3306」

我只是要與港口3307連接,但:3306汽車包括

我已經嘗試了一些方法,但一直沒有工作

我的主要配置:

'db' => array(
    'class' => 'CDbConnection', 
    'connectionString' => !empty($ini['db']['conn_str']) 
     ? $ini['db']['conn_str'] : 'mysql:host=localhost;dbname=xxx', 
    'username' => !empty($ini['db']['user']) 
     ? $ini['db']['user'] : 'root', 
    'password' => isset($ini['db']['password']) 
     ? $ini['db']['password'] : 'xxx', 
    'tablePrefix' => !empty($ini['db']['prefix']) 
     ? $ini['db']['prefix'] : 'dcl_', 
    'emulatePrepare' => true, 
    'charset' => 'utf8', 
    'schemaCachingDuration' => 86400, 
    'enableParamLogging' => TRUE, 
    'enableProfiling' => TRUE, 
), 

'dbmm' => array(
    'class' => 'CDbConnection', 
    'connectionString' => !empty($ini['dbmm']['conn_str']) 
     ? $ini['dbmm']['conn_str'] : 'mysql:host=localhost;dbname=xxx', 
    'username' => !empty($ini['dbmm']['user']) 
     ? $ini['dbmm']['user'] : 'root', 
    'password' => isset($ini['dbmm']['password']) 
     ? $ini['dbmm']['password'] : 'xxx', 
    'tablePrefix' => !empty($ini['dbmm']['prefix']) 
     ? $ini['dbmm']['prefix'] : 'mm_', 
    'emulatePrepare' => true, 
    'charset' => 'utf8', 
    'schemaCachingDuration' => 86400, 
    'enableParamLogging' => TRUE, 
    'enableProfiling' => TRUE, 
    'attributes' => array(
     PDO::MYSQL_ATTR_LOCAL_INFILE => true 
    ), 
), 

'dbantrian' => array(
    'class' => 'CDbConnection', 
    'connectionString' => !empty($ini['dbantrian']['conn_str']) 
     ? $ini['dbantrian']['conn_str'] : 'mysql:host=localhost;dbname=xxx', 
    'username' => !empty($ini['dbantrian']['user']) 
     ? $ini['dbantrian']['user'] : 'root', 
    'password' => isset($ini['dbantrian']['password']) 
     ? $ini['dbantrian']['password'] : 'xxx', 
    'emulatePrepare' => true, 
    'charset' => 'utf8', 
    'schemaCachingDuration' => 86400, 
    'enableParamLogging' => TRUE, 
    'enableProfiling' => TRUE, 
), 

我的.ini文件:

[db] 
conn_str = "mysql:host=localhost:3307;dbname=xxx" 
user = "root" 
password = "xxx" 
prefix = "dcl_" 

[dbmm] 
conn_str = "mysql:host=localhost:3307;dbname=xxx" 
user = "root" 
password = "xxx" 
prefix = "mm_" 

[dbantrian] 
conn_str = "mysql:host=localhost:3307;dbname=xxx" 
user = "root" 
password = "xxx" 

我使用的工具:

  • Ubuntu的16
  • Ajenti V
  • Nginx的
  • PHP 5.6
  • PDO和PDO Mysql的
  • MariaDB的5.7

,因爲我不允許更新的警予

核心文件,我不知道我錯過

我不能使用從 PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002]解決方案

感謝之前,我的英語

更新惋惜: 我對舊設備的應用程序有後錯誤(比如我的新的應用程序)

Setting up php5.6-common (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-curl (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-sqlite3 (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-mbstring (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-xml (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-gd (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-readline (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-mcrypt (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-json (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-mysql (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-opcache (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-cli (5.6.30-10+deb.sury.org~xenial+2) ... 
Setting up php5.6-fpm (5.6.30-10+deb.sury.org~xenial+2) ... 
NOTICE: Not enabling PHP 5.6 FPM by default. 
NOTICE: To enable PHP 5.6 FPM in Apache2 do: 
NOTICE: a2enmod proxy_fcgi setenvif 
NOTICE: a2enconf php5.6-fpm 
NOTICE: You are seeing this message because you have apache2 package installed. 
Setting up php-msgpack (2.0.2+0.5.7-1+deb.sury.org~xenial+2) ... 
Setting up php-mysql (1:7.1+52+deb.sury.org~xenial+1) ... 
Setting up php-pgsql (1:7.1+52+deb.sury.org~xenial+1) ... 
+0

你的PDO連接代碼是什麼樣的?編輯你的問題來增加它,它應該更明顯是什麼錯誤。 – tadman

+0

已編輯。我使用Yii1,所以我只是添加連接配置 – Baron

+0

解決。將'host = localhost:3307'改爲'host = 127.0.0.1; port = 3307' – Baron

回答

2

配置字符串應該是這樣的:

mysql:host=localhost;port=3307;... 

port部分必須從host分開。

+0

我試過這段代碼,但沒有工作。當我使用上面的方法時,yii像忽略的端口值 – Baron

+1

根據[Yii文檔](http)[PDO手冊](http://php.net/manual/en/pdo.construct.php) ://www.yiiframework.com/doc-2.0/guide-db-dao.html),所以我不知道該說什麼。 – tadman