Php Symfony 1.4通过SSL连接到mysql
我需要更改一个旧的Symfony 1.4应用程序,以便它能够通过ssl连接连接到mysql 对于Symfony>=2,我发现了很多关于此的信息。但不幸的是,对于这个尘土飞扬的人来说,情况并非如此 出于验证目的,我已经通过编辑使其工作 /apps/frontend/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctor/Connection.phpPhp Symfony 1.4通过SSL连接到mysql,php,mysql,ssl,doctrine,symfony-1.4,Php,Mysql,Ssl,Doctrine,Symfony 1.4,我需要更改一个旧的Symfony 1.4应用程序,以便它能够通过ssl连接连接到mysql 对于Symfony>=2,我发现了很多关于此的信息。但不幸的是,对于这个尘土飞扬的人来说,情况并非如此 出于验证目的,我已经通过编辑使其工作 /apps/frontend/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctor/Connection.php $this->dbh = new PDO($this->opt
$this->dbh = new PDO($this->options['dsn'], $this->options['username'],
(!$this->options['password'] ? '':$this->options['password']), array(PDO::ATTR_PERSISTENT => true));
到
但我想知道这个丑陋的黑客行为是否是唯一的解决方案?我花了一段时间才发现这个连接类已经被覆盖(apps/frontend/lib…) 所以我只需要让这些变量可配置。databases.yml配置中有一个名为attributes(条令::参数::属性)的选项。如果传递非字符串键,则可以使用getAttribute获取它们 所以,至少它是有效的(它在connect方法的try区域内) 在databases.yml中,您必须键入以下内容(注释有助于理解这些数字)
我花了一些时间才看到这个连接类已经被覆盖(apps/frontend/lib…) 所以我只需要让这些变量可配置。databases.yml配置中有一个名为attributes(条令::参数::属性)的选项。如果传递非字符串键,则可以使用getAttribute获取它们 所以,至少它是有效的(它在connect方法的try区域内) 在databases.yml中,您必须键入以下内容(注释有助于理解这些数字)
$this->dbh = new PDO($this->options['dsn'], $this->options['username'],
(!$this->options['password'] ? '':$this->options['password']),
array(PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_SSL_KEY => '/etc/my.cnf.d/ssl/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => '/etc/my.cnf.d/ssl/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => '/etc/my.cnf.d/ssl/ca-cert.pem'));
$sslOptionKeys = array(PDO::MYSQL_ATTR_SSL_KEY, PDO::MYSQL_ATTR_SSL_CERT, PDO::MYSQL_ATTR_SSL_CA);
foreach($sslOptionKeys as $sslOptionKey) {
if(array_key_exists($sslOptionKey, $this->pendingAttributes)) {
$pdoOptions[$sslOptionKey] = $this->getAttribute($sslOptionKey);
}
}
$this->dbh = new PDO($this->options['dsn'], $this->options['username'],
(!$this->options['password'] ? '':$this->options['password']),
$pdoOptions);
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=localhost;dbname=db
username: user
password: pass
encoding: utf8
attributes:
#PDO::MYSQL_ATTR_SSL_KEY
1010: /etc/my.cnf.d/ssl/client-key.pem
#PDO::MYSQL_ATTR_SSL_CERT
1011: /etc/my.cnf.d/ssl/client-cert.pem
#PDO::MYSQL_ATTR_SSL_CA
1012: /etc/my.cnf.d/ssl/ca-cert.pem