Reputation: 5736
Using this code I'm able to connect to mysql using zend framework normally:
resources.db.adapter = "Pdo_Mysql"
resources.db.params.host = "xx.xx.xx.xx"
resources.db.params.username = "test_user"
resources.db.params.password = "test_pass"
resources.db.params.dbname = "test_database"
resources.db.params.port="xxxx"
;parameters here for ssl connection??
In my Controller
:
public function indexAction() {
$config = new Zend_Config_Ini('/path/to/application.ini', 'development');
$db = Zend_Db::factory($config->resources->db);
$sql = 'SELECT * FROM test_table';
$result = $db->fetchAll($sql);
echo '<pre>';
print_r($result);
}
Now the problem is that I want to connect to mysql using ssl, but I haven't found any documentation on how to do that.
I managed to make a connection using Navicat to the server with the help of the database admin by configuring the ssl connection as follows:
The problem now is how to connect using php?
Upvotes: 7
Views: 3888
Reputation: 715
To connect with Zend set your application.ini like this :
;PDO::MYSQL_ATTR_SSL_KEY = 1007
resources.db.params.driver_options.1007 = "/path/to/client-key.pem"
;PDO::MYSQL_ATTR_SSL_CERT = 1008
resources.db.params.driver_options.1008 = "/path/to/client-cert.pem"
;PDO::MYSQL_ATTR_SSL_CA = 1009
resources.db.params.driver_options.1009 = "/path/to/ca-cert.pem"
Upvotes: 1
Reputation: 21
My working configuration for Zend Db (Adapter: Pdo_Mysql) over SSL:
Array
(
[host] => XX.XX.XX.XX
[username] => nice-user
[password] => ************
[dbname] => database
[driver_options] => Array
(
[1010] => /path/to/client-key.pem
[1011] => /path/to/client-cert.pem
[1012] => /path/to/ca-cert.pem
[1013] =>
[1014] => DHE-RSA-AES256-SHA
)
)
And make sure above listed certificate files are readable by Apache user ('www-data' on Debian) if your application is web based, which I assume it is.
Upvotes: 2
Reputation: 8830
You should be able to specify driver options like this:
;PDO::MYSQL_ATTR_SSL_KEY
resources.db.params.driver_options.1010 = "/path/to/client-key.pem"
;PDO::MYSQL_ATTR_SSL_CERT
resources.db.params.driver_options.1011 = "/path/to/client-cert.pem"
;PDO::MYSQL_ATTR_SSL_CA
resources.db.params.driver_options.1012 = "/path/to/ca-cert.pem"
Upvotes: 3
Reputation: 88647
From http://php.net/manual/en/ref.pdo-mysql.php:
SSL support is enabled using the appropriate PDO_MySQL constants, which is equivalent to calling the » MySQL C API function mysql_ssl_set(). Also, SSL cannot be enabled with PDO::setAttribute because the connection already exists. See also the MySQL documentation about » connecting to MySQL with SSL.
See also: http://php.net/manual/en/ref.pdo-mysql.php#103501
Your PHP installation will also need openssl in order for this to work correctly.
Upvotes: 2