From 8ebfb295ab1bd9261b1163bf7cf69ceaff6a0b9d Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Sat, 3 Jul 2021 13:37:26 +0800 Subject: [PATCH] modify --- Database/Connection.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Database/Connection.php b/Database/Connection.php index 09480340..4fb708dc 100644 --- a/Database/Connection.php +++ b/Database/Connection.php @@ -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);