Skip to content

Commit

Permalink
For MySQL you can now specify the socket to use using unix_socket k…
Browse files Browse the repository at this point in the history
…ey in the config array. Closes #1994
  • Loading branch information
ADmad committed Sep 16, 2011
1 parent 9d1e3cb commit 7c87e9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Config/database.php.default
Expand Up @@ -54,6 +54,8 @@
* For MySQL, Postgres specifies the character encoding to use when connecting to the
* database. Uses database default not specified.
*
* unix_socket =>
* For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port`
*/
class DATABASE_CONFIG {

Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Console/Templates/skel/Config/database.php.default
Expand Up @@ -54,6 +54,8 @@
* For MySQL, Postgres specifies the character encoding to use when connecting to the
* database. Uses database default not specified.
*
* unix_socket =>
* For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port`
*/
class DATABASE_CONFIG {

Expand Down
7 changes: 6 additions & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -147,8 +147,13 @@ public function connect() {
if (!empty($config['encoding'])) {
$flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
}
if (empty($config['unix_socket'])) {
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
} else {
$dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
}
$this->_connection = new PDO(
"mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}",
$dsn,
$config['login'],
$config['password'],
$flags
Expand Down

0 comments on commit 7c87e9a

Please sign in to comment.