modify
This commit is contained in:
@@ -266,6 +266,8 @@ class Connection extends Component
|
|||||||
public function createCommand($sql = null, $dbname = '', array $attributes = []): Command
|
public function createCommand($sql = null, $dbname = '', array $attributes = []): Command
|
||||||
{
|
{
|
||||||
$substr = strtoupper(substr($sql, 0, 6));
|
$substr = strtoupper(substr($sql, 0, 6));
|
||||||
|
|
||||||
|
if (!str_contains('`' . $dbname . '`', $sql)) {
|
||||||
$sql = match ($substr) {
|
$sql = match ($substr) {
|
||||||
'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+([a-zA-Z\-_]+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql),
|
'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+([a-zA-Z\-_]+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql),
|
||||||
'UPDATE' => preg_replace('/UPDATE\s+([a-zA-Z\-_]+)\s+SET/', 'UPDATE `' . $dbname . '`.$1 SET', $sql),
|
'UPDATE' => preg_replace('/UPDATE\s+([a-zA-Z\-_]+)\s+SET/', 'UPDATE `' . $dbname . '`.$1 SET', $sql),
|
||||||
@@ -273,9 +275,8 @@ class Connection extends Component
|
|||||||
'TRUNCA' => preg_replace('/TRUNCATE\s+([a-zA-Z\-_]+)\s+/', 'TRUNCATE `' . $dbname . '`.$1', $sql),
|
'TRUNCA' => preg_replace('/TRUNCATE\s+([a-zA-Z\-_]+)\s+/', 'TRUNCATE `' . $dbname . '`.$1', $sql),
|
||||||
default => throw new Exception('database error')
|
default => throw new Exception('database error')
|
||||||
};
|
};
|
||||||
|
}
|
||||||
$sql = preg_replace('/INNER JOIN\s+([a-zA-Z\-_]+)\s/', 'INNER JOIN `'.$dbname.'`.$1 ', $sql);
|
$sql = preg_replace('/INNER JOIN\s+([a-zA-Z\-_]+)\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