mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-02 14:25:38 +08:00
fix dbName bug
This commit is contained in:
@@ -24,19 +24,27 @@ class DBWrapper
|
|||||||
$db_type = $options['dbType'] ?? ZM_DB_POOL;
|
$db_type = $options['dbType'] ?? ZM_DB_POOL;
|
||||||
try {
|
try {
|
||||||
if ($db_type === ZM_DB_POOL) {
|
if ($db_type === ZM_DB_POOL) {
|
||||||
|
// 设置 dbName
|
||||||
|
$options['dbName'] = $name;
|
||||||
// pool 为连接池格式
|
// pool 为连接池格式
|
||||||
$db_list = config()->get('global.database');
|
$db_list = config()->get('global.database');
|
||||||
if (isset($db_list[$name]) || (is_countable($db_list) ? count($db_list) : 0) === 1) {
|
if (isset($db_list[$name]) || (is_countable($db_list) ? count($db_list) : 0) === 1) {
|
||||||
if ($name === '') {
|
if ($name === '') {
|
||||||
$name = array_key_first($db_list);
|
$name = array_key_first($db_list);
|
||||||
}
|
}
|
||||||
$this->connection = DriverManager::getConnection(['driverClass' => $this->getConnectionClass($db_list[$name]['type']), ...$options]);
|
$this->connection = DriverManager::getConnection(array_merge(
|
||||||
|
['driverClass' => $this->getConnectionClass($db_list[$name]['type']), 'dbName' => $name],
|
||||||
|
$options
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
throw new DBException('Cannot find database config named "' . $name . '" !');
|
throw new DBException('Cannot find database config named "' . $name . '" !');
|
||||||
}
|
}
|
||||||
} elseif ($db_type === ZM_DB_PORTABLE) {
|
} elseif ($db_type === ZM_DB_PORTABLE) {
|
||||||
// portable 为sqlite单文件模式
|
// portable 为sqlite单文件模式
|
||||||
$this->connection = DriverManager::getConnection(['driverClass' => SQLiteDriver::class, 'filename' => $name, ...$options]);
|
$this->connection = DriverManager::getConnection(array_merge(
|
||||||
|
['driverClass' => SQLiteDriver::class, 'filename' => $name],
|
||||||
|
$options
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
||||||
|
|||||||
Reference in New Issue
Block a user