/** * @param $sql * @param $params * @param bool|false $get_insert_id * @return bool|int|\mysqli_result */ private function prepareQuery($sql, $params, $get_insert_id = false) { $stmt = $this->mysqli->stmt_init(); if ($stmt->prepare($sql) === false || call_user_func_array([$stmt, 'bind_param'], self::refValues($params)) === false || $stmt->execute() === false || ($result = $stmt->get_result()) === false) { ErrorHandler::insertErrorInLogs("DB_ERROR[{$stmt->errno}]", $stmt->error, 'liw\\core\\model\\connect\\ConnectMysqli', '87'); return false; } if ($get_insert_id) { if (($result = $stmt->insert_id) === false) { ErrorHandler::insertErrorInLogs("DB_ERROR[{$stmt->errno}]", $stmt->error, 'liw\\core\\model\\connect\\ConnectMysqli', '92'); return false; } } $stmt->close(); if (isset($result)) { return $result; } return true; }
/** * Метод сохраняет в базе данных массив fields * @return mixed : 1. id - сохраненной модели, если у нее есть поле AI в случае успешного сохранение * 2. true - в случае успешного сохранение, но в отсутствие поля с AI * 3. false - в случае неудачного сохранения * @throws \Exception */ public function save() { if (!empty($this->fields)) { if (!empty($this->rules())) { $arr_keys = $this->addFieldsFromRules(); } else { $arr_keys = array_keys($this->fields); } if (method_exists($this, 'validate')) { if ($this->validate() && ($id = $this->insert($arr_keys)->push())) { if ($id !== true) { $this->fields['id'] = $id; } return true; } else { return false; } } else { if ($id = $this->insert($arr_keys)->push()) { if ($id !== true) { $this->id = $id; } return true; } else { return false; } } } else { ErrorHandler::insertErrorInLogs("ERROR_SAVE_MODEL", Lang::uage('error_save_model'), 'liw\\core\\Model', '309'); return false; } }