Browse Source

For MySQL you can now specify the socket to use using `unix_socket` key in the config array. Closes #1994

ADmad 14 years ago
parent
commit
7c87e9abc1

+ 2 - 0
app/Config/database.php.default

@@ -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 {
 

+ 2 - 0
lib/Cake/Console/Templates/skel/Config/database.php.default

@@ -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 {
 

+ 6 - 1
lib/Cake/Model/Datasource/Database/Mysql.php

@@ -147,8 +147,13 @@ class Mysql extends DboSource {
 			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