Skip to content

Commit

Permalink
Extended MySQL Adapter to allow the use of unix_sockets as well as TC…
Browse files Browse the repository at this point in the history
…P/IP connections.

Moved creation of mysql dsn into a separate function to allow decision wether to use unix_socket or tcp socket connection.
  • Loading branch information
drewsonne committed Mar 3, 2013
1 parent 87974f0 commit 6b8cc20
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/adapters/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function connect($host = false, $port = false, $username = false, $passwo
$this->database_name = $database_name; // the DB name is later used to restrict SHOW PROCEDURE STATUS and SHOW_FUNCTION_STATUS to the current database

try {
$this->_connection = new PDO("mysql:host=$host;port=$port;dbname=$database_name", $username, $password, array(
$this->_connection = new PDO($this->_buildDsn($host, $port, $database_name), $username, $password, array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Expand All @@ -25,6 +25,16 @@ public function connect($host = false, $port = false, $username = false, $passwo
}
}

protected function _buildDsn($host = false, $port = false, $database_name = false)
{
if($host[0] == "/") {
$location = "unix_socket=$host";
} else {
$location = "host=$host;port=$port";
}
return "mysql:$location;dbname=$database_name";
}

public function query($sql)
{
try {
Expand Down

0 comments on commit 6b8cc20

Please sign in to comment.