Skip to content

Commit

Permalink
改进mysql驱动对socket支持
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 13, 2017
1 parent 568864e commit 926c9ed
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions library/think/db/connector/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ class Mysql extends Connection
*/
protected function parseDsn($config)
{
$dsn = 'mysql:dbname=' . $config['database'] . ';host=' . $config['hostname'];
if (!empty($config['hostport'])) {
$dsn .= ';port=' . $config['hostport'];
} elseif (!empty($config['socket'])) {
$dsn .= ';unix_socket=' . $config['socket'];
if (!empty($config['socket'])) {
$dsn = 'mysql:unix_socket=' . $config['socket'];
} elseif (!empty($config['hostport'])) {
$dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport'];
} else {
$dsn = 'mysql:host=' . $config['hostname'];
}
$dsn .= ';dbname=' . $config['database'];

if (!empty($config['charset'])) {
$dsn .= ';charset=' . $config['charset'];
}
Expand Down

0 comments on commit 926c9ed

Please sign in to comment.