/** * @param ContactModel $model * @see ControllerBase::update() */ public function update($model) { if ($model->validateForUpdate()) { try { $query = <<<SQL UPDATE contact SET contactCompanyId = ? , contactName = ? , contactEmail = ? , contactPhone = ? , contactAlternatePhone = ? WHERE id = ? SQL; $id = $model->getId(); $contactCompanyId = $model->getContactCompanyId(); $contactName = $model->getContactName(); $contactEmail = $model->getContactEmail(); $contactPhone = $model->getContactPhone(); $contactAlternatePhone = $model->getContactAlternatePhone(); $stmt = $this->_dbh->prepare($query); if (!$stmt) { throw new ControllerException('Prepared statement failed for ' . $query); } if (!$stmt->bind_param('issssi', $contactCompanyId, $contactName, $contactEmail, $contactPhone, $contactAlternatePhone, $id)) { throw new ControllerException('Binding parameters for prepared statement failed.'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute UPDATE statement. (' . $this->_dbh->error . ')'); } /** * @SuppressWarnings checkAliases */ if (!$stmt->close()) { throw new ControllerException('Something broke while trying to close the prepared statement.'); } return $id; } catch (Exception $e) { throw new ControllerException($e->getMessage()); } } else { throw new ControllerException("Invalid data."); } }