From cda9320e969c90e718b1581054efc1b095efa523 Mon Sep 17 00:00:00 2001 From: Rob Spencer Date: Thu, 21 Nov 2013 21:35:29 -0500 Subject: [PATCH 1/2] Added support for passing additional flags to mysql connection --- app/Config/database.php.default | 3 +++ lib/Cake/Console/Templates/skel/Config/database.php.default | 5 ++++- lib/Cake/Model/Datasource/Database/Mysql.php | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Config/database.php.default b/app/Config/database.php.default index 42fedb60a..767c01095 100644 --- a/app/Config/database.php.default +++ b/app/Config/database.php.default @@ -58,6 +58,9 @@ * For MySQL : http://dev.mysql.com/doc/refman/5.6/en/set-statement.html * For Postgres : http://www.postgresql.org/docs/9.2/static/sql-set.html * For Sql Server : http://msdn.microsoft.com/en-us/library/ms190356.aspx + * + * flags => + * A key/value array of driver specific connection options. */ class DATABASE_CONFIG { diff --git a/lib/Cake/Console/Templates/skel/Config/database.php.default b/lib/Cake/Console/Templates/skel/Config/database.php.default index fdefd4161..00ad15507 100644 --- a/lib/Cake/Console/Templates/skel/Config/database.php.default +++ b/lib/Cake/Console/Templates/skel/Config/database.php.default @@ -41,12 +41,15 @@ * * unix_socket => * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port` - + * * settings => * Array of key/value pairs, on connection it executes SET statements for each pair * For MySQL : http://dev.mysql.com/doc/refman/5.6/en/set-statement.html * For Postgres : http://www.postgresql.org/docs/9.2/static/sql-set.html * For Sql Server : http://msdn.microsoft.com/en-us/library/ms190356.aspx + * + * flags => + * A key/value array of driver specific connection options. */ class DATABASE_CONFIG { diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index d2b53d561..4f1d16819 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -45,7 +45,8 @@ class Mysql extends DboSource { 'login' => 'root', 'password' => '', 'database' => 'cake', - 'port' => '3306' + 'port' => '3306', + 'flags' => array() ); /** @@ -145,7 +146,7 @@ class Mysql extends DboSource { $config = $this->config; $this->connected = false; - $flags = array( + $flags = $config['flags'] + array( PDO::ATTR_PERSISTENT => $config['persistent'], PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION From b8e32dd2b373adee9bf5920d571b4bca4315c38d Mon Sep 17 00:00:00 2001 From: Rob Spencer Date: Sun, 24 Nov 2013 01:04:17 -0500 Subject: [PATCH 2/2] Adding flags override to additional pdo drivers --- lib/Cake/Model/Datasource/Database/Postgres.php | 5 +++-- lib/Cake/Model/Datasource/Database/Sqlite.php | 5 +++-- lib/Cake/Model/Datasource/Database/Sqlserver.php | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index fc2966140..81a25e013 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -45,7 +45,8 @@ class Postgres extends DboSource { 'database' => 'cake', 'schema' => 'public', 'port' => 5432, - 'encoding' => '' + 'encoding' => '', + 'flags' => array() ); /** @@ -110,7 +111,7 @@ class Postgres extends DboSource { $config = $this->config; $this->connected = false; - $flags = array( + $flags = $config['flags'] + array( PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 6689139b6..5d0cc43e8 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -56,7 +56,8 @@ class Sqlite extends DboSource { */ protected $_baseConfig = array( 'persistent' => false, - 'database' => null + 'database' => null, + 'flags' => array() ); /** @@ -106,7 +107,7 @@ class Sqlite extends DboSource { */ public function connect() { $config = $this->config; - $flags = array( + $flags = $config['flags'] + array( PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 831616a39..64342f720 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -78,6 +78,7 @@ class Sqlserver extends DboSource { 'password' => '', 'database' => 'cake', 'schema' => '', + 'flags' => array() ); /** @@ -119,7 +120,7 @@ class Sqlserver extends DboSource { $config = $this->config; $this->connected = false; - $flags = array( + $flags = $config['flags'] + array( PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION );