在我安装我的应用程序并且工作正常之前,但是当我使用相同的代码和配置在其他设备上进行新安装时, 我在 yii 1 上尝试使用 pdo 扩展连接隧道 mysql 时遇到错误。
错误信息如下:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Failed to parse address "localhost: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
- 阿杰蒂五号
- Nginx
- PHP 5.6
- PDO 和 PDO Mysql
- MariaDB 5.7
我无法使用 PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002] 中的解决方案因为我不允许更新 yii 的核心文件
我不知道我错过了什么
谢谢之前,对我的英语感到抱歉
更新:
我在旧设备上的应用程序在 sudo apt upgrade
之后出现错误(就像在我的新应用程序上一样)
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) ...
最佳答案
配置字符串应如下所示:
mysql:host=localhost;port=3307;...
端口
部分必须与主机
分开。
关于PHP PDO MySQL 隧道连接双端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43624951/