在我安装我的应用程序之前工作正常但是当我在具有相同代码和配置的其他设备上进行新安装时, 尝试在 yii 1 上连接隧道mysql和pdo扩展时出错。
错误信息如下:
CDbConnection无法打开数据库连接:SQLSTATE [HY000] [2002]无法解析地址“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"
我使用的工具:
我无法使用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) ...
答案 0 :(得分:2)
配置字符串应如下所示:
if(!(fromDate.after(currentDate))){
addFieldError("fromDate","The date is Older");
}
mysql:host=localhost;port=3307;...
部分必须与port
分开。