From 1fcdd54c94c3bb677acf8ce04c5a547af931227c Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 25 Jul 2024 15:43:42 +0200 Subject: [PATCH] Patching from master OTS_House refactor code + $db->update with nulls --- system/libs/pot/OTS_Base_DB.php | 10 ++++++++-- system/libs/pot/OTS_House.php | 7 +------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/system/libs/pot/OTS_Base_DB.php b/system/libs/pot/OTS_Base_DB.php index 21d6f756..6ef39bc5 100644 --- a/system/libs/pot/OTS_Base_DB.php +++ b/system/libs/pot/OTS_Base_DB.php @@ -184,8 +184,14 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB $query = 'UPDATE '.$this->tableName($table).' SET '; $count = count($fields); - for ($i = 0; $i < $count; $i++) - $query.= $this->fieldName($fields[$i]).' = '.$this->quote($values[$i]).', '; + for ($i = 0; $i < $count; $i++) { + $value = 'NULL'; + if ($values[$i] !== null) { + $value = $this->quote($values[$i]); + } + + $query.= $this->fieldName($fields[$i]).' = '.$value.', '; + } $query = substr($query, 0, -2); $query.=' WHERE ('; diff --git a/system/libs/pot/OTS_House.php b/system/libs/pot/OTS_House.php index 12a8f1cb..9ef0c149 100644 --- a/system/libs/pot/OTS_House.php +++ b/system/libs/pot/OTS_House.php @@ -60,12 +60,7 @@ class OTS_House extends OTS_Row_DAO private $tiles = array(); public function load($id) { - $this->data = $this->db->query('SELECT * FROM `houses` WHERE `id` = ' . $id )->fetch(); - foreach($this->data as $key => $value) { - if(is_numeric($key)) { - unset($this->data[$key]); - } - } + $this->data = $this->db->query('SELECT * FROM `houses` WHERE `id` = ' . $id )->fetch(PDO::FETCH_ASSOC); } public function find($name)