/** * @param SearchModel $model * @see ControllerBase::update() */ public function update($model) { if ($model->validateForUpdate()) { try { $query = <<<SQL UPDATE search SET engineName = ? , searchName = ? , url = ? WHERE id = ? SQL; $id = $model->getId(); $engineName = $model->getEngineName(); $searchName = $model->getSearchName(); $url = $model->getUrl(); $stmt = $this->_dbh->prepare($query); if (!$stmt) { throw new ControllerException('Prepared statement failed for ' . $query); } if (!$stmt->bind_param('sssi', $engineName, $searchName, $url, $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."); } }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ require_once "Libs/autoload.php"; $config = new Config(); $webPage = new PJSWebPage($config->getTitle() . ' - Edit Search'); $act = Tools::Param('act'); if ("Edit Search" === $act) { $searchModel = new SearchModel(); $searchModel->populateFromForm(); if (!$searchModel->validateForUpdate()) { $view = new SearchFormView('Edit Search', $searchModel); $body = "<h2>Invalid data</h2>\n" . $view->getForm(); } else { $searchController = new SearchController(); $newId = $searchController->update($searchModel); if ($newId > 0) { $body = "Edited search: " . $searchModel->getSearchName() . " as # " . $newId . "<br />\n"; } } } else { $searchController = new SearchController(); $searchModel = $searchController->get(Tools::param('id')); $view = new SearchFormView('Edit Search', $searchModel); $body = $view->getForm(); }