Symfony2教义通过SSL连接到数据库 [英] Symfony2 doctrine connect to database via SSL
问题描述
尝试通过SSL连接到我的MySQL数据库,我已经通过ssh通过以下命令行成功地建立了我的网络服务器的连接:
Trying to connect to my MySQL database via SSL, I have successfully established the connection from my webserver via ssh with the following command line:
mysql -h my.host.here --port=5454 -v --ssl-ca=/etc/apache2/ssl/mysql/ca-cert.pem --ssl-cert=/etc/apache2/ssl/mysql/client-cert.pem --ssl-key=/etc/apache2/ssl/mysql/client-key.pem -u user -p
但是,尝试在symfony2和doctrine中设置相同的连接,所有我不断得到的是SSL错误
However, trying to set up the same connection in symfony2 and doctrine, all I keep getting is an "SSL error"
$params = array(
'driver' => 'pdo_mysql',
'user' => 'user',
'password' => 'pass',
'host' => 'my.host.here',
'dbname' => 'media',
'port' => '5454',
);
if($this->container->hasParameter('media_ca') && $this->container->hasParameter('media_cert') && $this->container->hasParameter('media_key')) {
$params['driverOptions'] = array(
PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->hasParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->hasParameter('media_key'),
);
}
/* Using this instead with only the ca_cert gives me the same error
if($this->container->hasParameter('media_ca')) {
$params['driverOptions'] = array(
PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
);
}
*/
$connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
$conn = $connectionFactory->createConnection($params);
return $conn;
在我的日志中:
[2013-10-01 15:23:30] request.CRITICAL:未捕获PHP异常PDOException:SQLSTATE [HY000] [2026] SSL连接错误/ var / www / mysite / vendor / doctrine / dbal / lib / Doctrine / DBAL / Driver / PDOConnection.php line 36 {exception:[object](PDOException:SQLSTATE [HY000] [2026] / var / www / mysite / vendor / doctrine / dbal中的SSL连接错误/lib/Doctrine/DBAL/Driver/PDOConnection.php:36)} []
[2013-10-01 15:23:30] request.CRITICAL: Uncaught PHP Exception PDOException: "SQLSTATE[HY000] [2026] SSL connection error" at /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36 {"exception":"[object] (PDOException: SQLSTATE[HY000] [2026] SSL connection error at /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:36)"} []
我已经双重检查了网络服务器用户www-data)可以访问证书文件,并且那些证书文件的路径是正确的(在symfony2参数中定义)。
I have doublechecked that the webserver user (www-data) has access to the certificate files, and that the path to those cert files are correct (defined in the symfony2 parameters).
我不能想到任何东西否则我的命令行连接和我用doctrine / symfony2指定的连接是不同的。
I can not think of anything else that is different between my command line connection and the one I have specified with doctrine/symfony2.
推荐答案
参数。您需要 getParameter($ param)
方法,而不是 hasParameter($ param)
。这些行是正确的。
You are wrong with retrieving parameters. You need getParameter($param)
method instead of hasParameter($param)
. These lines are correct.
PDO::MYSQL_ATTR_SSL_CA => $this->container->getParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->getParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->getParameter('media_key'),
这篇关于Symfony2教义通过SSL连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!