modify
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user