mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
修正Db类的parseDsn方法
This commit is contained in:
@@ -39,6 +39,9 @@ class Db
|
|||||||
if (!isset(self::$instances[$md5])) {
|
if (!isset(self::$instances[$md5])) {
|
||||||
// 解析连接参数 支持数组和字符串
|
// 解析连接参数 支持数组和字符串
|
||||||
$options = self::parseConfig($config);
|
$options = self::parseConfig($config);
|
||||||
|
if (empty($options['type'])) {
|
||||||
|
throw new Exception('db type error');
|
||||||
|
}
|
||||||
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
||||||
$class = $lite ? '\\think\\db\\Lite' : (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
|
$class = $lite ? '\\think\\db\\Lite' : (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
|
||||||
self::$instances[$md5] = new $class($options);
|
self::$instances[$md5] = new $class($options);
|
||||||
@@ -80,10 +83,9 @@ class Db
|
|||||||
*/
|
*/
|
||||||
private static function parseDsn($dsnStr)
|
private static function parseDsn($dsnStr)
|
||||||
{
|
{
|
||||||
if (empty($dsnStr)) {return false;}
|
|
||||||
$info = parse_url($dsnStr);
|
$info = parse_url($dsnStr);
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
return false;
|
return [];
|
||||||
}
|
}
|
||||||
$dsn = [
|
$dsn = [
|
||||||
'type' => $info['scheme'],
|
'type' => $info['scheme'],
|
||||||
@@ -91,7 +93,7 @@ class Db
|
|||||||
'password' => isset($info['pass']) ? $info['pass'] : '',
|
'password' => isset($info['pass']) ? $info['pass'] : '',
|
||||||
'hostname' => isset($info['host']) ? $info['host'] : '',
|
'hostname' => isset($info['host']) ? $info['host'] : '',
|
||||||
'hostport' => isset($info['port']) ? $info['port'] : '',
|
'hostport' => isset($info['port']) ? $info['port'] : '',
|
||||||
'database' => isset($info['path']) ? substr($info['path'], 1) : '',
|
'database' => !empty($info['path']) ? ltrim($info['path'], '/') : '',
|
||||||
'charset' => isset($info['fragment']) ? $info['fragment'] : 'utf8',
|
'charset' => isset($info['fragment']) ? $info['fragment'] : 'utf8',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user