Db: add parse_pdo_dsn() helper method
This commit is contained in:
parent
9030a2ba79
commit
a3156d4d05
1 changed files with 18 additions and 0 deletions
18
src/Db.php
18
src/Db.php
|
@ -469,4 +469,22 @@ class Db {
|
|||
$row[$field] = $this -> date2time($row[$field]);
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to parse PHP PDO DSN info
|
||||
* @param string $dsn PHP PDO DSN to parse
|
||||
* @return array|false
|
||||
*/
|
||||
public static function parse_pdo_dsn($dsn) {
|
||||
if (!preg_match('/^([^:]+):(.+)$/', $dsn, $dsn_parts))
|
||||
return false;
|
||||
|
||||
$info = ['protocol' => $dsn_parts[1]];
|
||||
foreach(preg_split('/;+/', $dsn_parts[2]) as $part) {
|
||||
if (preg_match('/^([^=]+)=(.*)$/', $part, $dsn_part))
|
||||
$info[$dsn_part[1]] = $dsn_part[2];
|
||||
}
|
||||
Log::trace('parse_pdo_dsn(%s): %s', $dsn, vardump($info));
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue