This commit is contained in:
as2252258@163.com
2021-07-03 13:37:26 +08:00
parent 49892feff4
commit 8ebfb295ab
+8 -1
View File
@@ -265,7 +265,14 @@ class Connection extends Component
*/
public function createCommand($sql = null, array $attributes = []): Command
{
$sql = preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $this->database . '`.$1 ', $sql);
$substr = strtoupper(substr($sql, 0, 6));
$sql = match ($substr) {
'SELECT' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $this->database . '`.$1 ', $sql),
'UPDATE' => preg_replace('/UPDATE\s+(\w+)\s+SET/', 'UPDATE `' . $this->database . '`.$1 SET', $sql),
'DELETE' => preg_replace('/DELETE FROM\s+(\w+)\s+/', 'DELETE FROM `' . $this->database . '`.$1', $sql),
'INSERT' => preg_replace('/INSERT INTO\s+(\w+)\s+/', 'INSERT INTO `' . $this->database . '`.$1', $sql),
};
$command = new Command(['db' => $this, 'sql' => $sql]);
return $command->bindValues($attributes);