* support for database persistent and socket connections (performance boost)

This commit is contained in:
slawkens
2018-06-01 18:56:57 +02:00
parent adbec47fad
commit 510459b046
3 changed files with 39 additions and 14 deletions

View File

@@ -64,16 +64,6 @@ class OTS_DB_MySQL extends OTS_Base_DB
$params['port'] = $host[1];
}
if( isset($params['host']) )
{
$dns[] = 'host=' . $params['host'];
}
if( isset($params['port']) )
{
$dns[] = 'port=' . $params['port'];
}
if( isset($params['database']) )
{
$dns[] = 'dbname=' . $params['database'];
@@ -99,6 +89,10 @@ class OTS_DB_MySQL extends OTS_Base_DB
$this->logged = true;
}
if( !isset($params['persistent']) ) {
$params['persistent'] = false;
}
global $cache, $config;
if(isset($cache) && $cache->enabled()) {
$tmp = null;
@@ -123,7 +117,27 @@ class OTS_DB_MySQL extends OTS_Base_DB
}
}
parent::__construct('mysql:' . implode(';', $dns), $user, $password);
if(isset($params['socket'][0])) {
$dns[] = 'unix_socket=' . $params['socket'];
parent::__construct('mysql:' . implode(';', $dns), $user, $password, array(
PDO::ATTR_PERSISTENT => $params['persistent']
));
return;
}
if( isset($params['host']) ) {
$dns[] = 'host=' . $params['host'];
}
if( isset($params['port']) ) {
$dns[] = 'port=' . $params['port'];
}
parent::__construct('mysql:' . implode(';', $dns), $user, $password, array(
PDO::ATTR_PERSISTENT => $params['persistent']
));
}
public function __destruct()