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()
->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
{
if (!empty($dbname)) {
$substr = strtoupper(substr($sql, 0, 6));
$sql = match ($substr) {
'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')
};
$sql = preg_replace('/INNER JOIN\s+(\w+)\s/', 'INNER JOIN `' . $dbname . '`.$1 ', $sql);
}
$command = new Command(['db' => $this, 'sql' => $sql]);
return $command->bindValues($attributes);
}