我有一个YII 1应用程序。我试图连接到Azure数据库。
如果禁用该选项,则可以连接Azure数据库:强制SSL连接
但我当然想启用这个选项。
但如果启用此选项,则会出现以下错误:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
CWebUser.php(146)
134
135 /**
136 * PHP magic method.
137 * This method is overridden so that persistent states can be accessed like properties.
138 * @param string $name property name
139 * @return mixed property value
140 */
141 public function __get($name)
142 {
143 if($this->hasState($name))
144 return $this->getState($name);
145 else
146 return parent::__get($name);
147 }
148
149 /**
150 * PHP magic method.
151 * This method is overridden so that persistent states can be set like properties.
152 * @param string $name property name
153 * @param mixed $value property value
154 * @throws CException
155 */
156 public function __set($name,$value)
157 {
158 if($this->hasState($name))
我在中的main.php看起来像这样:
'db'=> [
'pdoClass' => 'NestedPDO',
'connectionString' => 'mysql:host=host_name;dbname=db_name',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'enableProfiling'=>true,
],
'cache'=>[
'class'=>'system.caching.CDbCache',
],
所以我的问题是:这部分配置中缺少什么?
谢谢你
如果我这样尝试:
'db'=> [
'pdoClass' => 'NestedPDO',
'connectionString' => 'mysql:host=host_name;dbname=db_name',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'enableProfiling'=>true,
'attributes' =>[
PDO::MYSQL_ATTR_SSL_CA => 'path ssl'
]
我得到这个错误:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] (trying to connect via (null))
在mysql workbrench中,如果我测试ssl证书,我会得到一个成功的响应。
1条答案
按热度按时间hc2pp10m1#
CDbConnection无法打开数据库连接:SQLSTATE[HY000] [2002](尝试通过(空)连接)
按照toffler的建议,添加评论作为社区wiki答案,以帮助可能面临类似问题的社区成员。
根据How to use SSL in PHP Data Objects (PDO) mysql添加
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
后,错误得到解决