This commit is contained in:
as2252258@163.com
2021-07-03 16:42:01 +08:00
parent 5e8676b844
commit 3399c31e70
2 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -1060,7 +1060,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
{ {
return static::getDb()->getSchema() return static::getDb()->getSchema()
->getColumns() ->getColumns()
->table(static::getTable()); ->table('`' . static::getDbName() . '`.' . static::getTable());
} }
/** /**
+2
View File
@@ -265,6 +265,7 @@ class Connection extends Component
*/ */
public function createCommand($sql = null, $dbname = '', array $attributes = []): Command public function createCommand($sql = null, $dbname = '', array $attributes = []): Command
{ {
if (!empty($dbname)) {
$substr = strtoupper(substr($sql, 0, 6)); $substr = strtoupper(substr($sql, 0, 6));
$sql = match ($substr) { $sql = match ($substr) {
'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql), 'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql),
@@ -274,6 +275,7 @@ class Connection extends Component
default => throw new Exception('database error') default => throw new Exception('database error')
}; };
$sql = preg_replace('/INNER JOIN\s+(\w+)\s/', 'INNER JOIN `' . $dbname . '`.$1 ', $sql); $sql = preg_replace('/INNER JOIN\s+(\w+)\s/', 'INNER JOIN `' . $dbname . '`.$1 ', $sql);
}
$command = new Command(['db' => $this, 'sql' => $sql]); $command = new Command(['db' => $this, 'sql' => $sql]);
return $command->bindValues($attributes); return $command->bindValues($attributes);
} }