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