/** * @param KeywordModel $model * @see ControllerBase::add() */ public function add($model) { if ($model->validateForAdd()) { try { $query = <<<SQL INSERT keyword ( id , keywordValue , sortKey , created , updated ) VALUES ( NULL, ?, ?, NOW(), NOW() ) SQL; $id = $model->getId(); $keywordValue = $model->getKeywordValue(); $sortKey = $model->getSortKey(); $stmt = $this->_dbh->prepare($query); if (!$stmt) { throw new ControllerException('Prepared statement failed for ' . $query); } if (!$stmt->bind_param('si', $keywordValue, $sortKey)) { throw new ControllerException('Binding parameters for prepared statement failed.'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute INSERT statement. (' . $this->_dbh->error . ')'); } $newId = $stmt->insert_id; /** * @SuppressWarnings checkAliases */ if (!$stmt->close()) { throw new ControllerException('Something broke while trying to close the prepared statement.'); } return $newId; } catch (Exception $e) { throw new ControllerException($e->getMessage()); } } else { throw new ControllerException("Invalid data."); } }