modify
This commit is contained in:
@@ -734,16 +734,16 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
||||
}
|
||||
|
||||
if (str_starts_with($table, $tablePrefix)) {
|
||||
return '`' . static::getDbName() . '`.' . $table;
|
||||
return $table;
|
||||
} else if (!str_starts_with($table, '{{%')) {
|
||||
return '`' . static::getDbName() . '`.' . $table;
|
||||
return $table;
|
||||
}
|
||||
|
||||
$table = trim($table, '{{%}}');
|
||||
if ($tablePrefix) {
|
||||
$table = $tablePrefix . $table;
|
||||
}
|
||||
return '`' . static::getDbName() . '`.' . $table;
|
||||
return $table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -265,15 +265,14 @@ class Connection extends Component
|
||||
*/
|
||||
public function createCommand($sql = null, $dbname = '', array $attributes = []): Command
|
||||
{
|
||||
// $substr = strtoupper(substr($sql, 0, 6));
|
||||
// $sql = match ($substr) {
|
||||
// 'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql),
|
||||
// 'UPDATE' => preg_replace('/UPDATE\s+(\w+)\s+SET/', 'UPDATE `' . $dbname . '`.$1 SET', $sql),
|
||||
// 'INSERT' => preg_replace('/INSERT INTO\s+(\w+)/', 'INSERT INTO `' . $dbname . '`.$1', $sql),
|
||||
// 'TRUNCA' => preg_replace('/TRUNCATE\s+(\w+)\s+/', 'TRUNCATE `' . $dbname . '`.$1', $sql),
|
||||
// default => throw new Exception('database error')
|
||||
// };
|
||||
|
||||
$substr = strtoupper(substr($sql, 0, 6));
|
||||
$sql = match ($substr) {
|
||||
'SELECT', 'SHOW F', 'DELETE' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql),
|
||||
'UPDATE' => preg_replace('/UPDATE\s+(\w+)\s+SET/', 'UPDATE `' . $dbname . '`.$1 SET', $sql),
|
||||
'INSERT' => preg_replace('/INSERT INTO\s+(\w+)/', 'INSERT INTO `' . $dbname . '`.$1', $sql),
|
||||
'TRUNCA' => preg_replace('/TRUNCATE\s+(\w+)\s+/', 'TRUNCATE `' . $dbname . '`.$1', $sql),
|
||||
default => throw new Exception('database error')
|
||||
};
|
||||
$command = new Command(['db' => $this, 'sql' => $sql]);
|
||||
return $command->bindValues($attributes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user