function deleting($table, $where) { $q = new Query(); $q->table = $table; $q->where = $where; $q->delete(); }
static function delete($id) { $tname = static::tableName(); $query = new Query($tname); $pk = static::$primaryKey; $query->delete($tname)->where("`{$tname}`.`{$pk}` = ?", [$id]); static::query($query, $query->params); }
/** * Delete a model from the database. * * @param int $id * @return int */ public function delete($id = null) { // If the delete method is being called on an existing model, we only want to delete // that model. If it is being called from an Eloquent query model, it is probably // the developer's intention to delete more than one model, so we will pass the // delete statement to the query instance. if (!$this->exists) { return $this->query->delete(); } return DB::connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id); }
protected function removeRelation($object) { if (!isset($this->owner)) { return false; } // can't add without $owner = $this->owner; $joint = static::tableJoin($owner->tableName, $object->tableName); // get the joint table $query = new Query($joint); $query->delete($joint)->where("{$object->tableName} = ? AND {$owner->tableName} = ?", [$object->primaryKey, $owner->primaryKey]); static::query($query, $query->params); }
public function process($get, $post) { if (!isset($post['course_id']) || !is_numeric($post['course_id']) || !isset($_COOKIE['sessionId']) || !is_numeric($_COOKIE['sessionId'])) { $this->failureReason = 'Sorry, there was an error.'; return false; } $query = new Query('action'); // Select all the courses that are in this user's session and have this course id $result = $query->delete(array(array('course_id', '=', $post['course_id']), array('session_id', '=', $_COOKIE['sessionId']))); if (!$result) { // Abort because this course is already in the user's model $this->failureReason = 'Sorry, there was an error.'; return false; } return true; }
public function delSoporte($soporte) { return $this->_query->delete($soporte); }
<?php include "sources/funciones.php"; if ($_SESSION["Activa"] and $_SESSION["Tipo_usuario"] == "administrador" and $_GET) { $id = $_GET['id']; require "sources/Query.inc"; $query = new Query(); if ($query->delete("dependencia", "idDependencia={$id}")) { $respuesta = ' <img src="images/ok.png" width="100"> <h4> Dependencia eliminada correctamente. </h4> '; } else { $respuesta = ' <img src="images/error.png" width="100"> <h4> Ha ocurrido un error. </h4> '; } ?> <!DOCTYPE html> <html> <head> <?php include 'sources/template/head.php'; ?> <meta http-equiv="Refresh" content="2;url=consultarDependencia.php" /> </head>
/** * Create delete query * * @param string $table * @param string $handler * @return mixed */ public static function delete($table, $handler = null) { return Query::delete($table, $handler); }
<?php include "sources/funciones.php"; if ($_SESSION["Activa"] and $_SESSION["Tipo_usuario"] == "administrador" and $_GET) { $id = $_GET['id']; require "sources/Query.inc"; $query = new Query(); if ($query->delete("redaccion", "idRedaccion={$id}")) { $respuesta = ' <img src="images/ok.png" width="100"> <h4> Saludo eliminado correctamente. </h4> '; } else { $respuesta = ' <img src="images/error.png" width="100"> <h4> Ha ocurrido un error. </h4> '; } ?> <!DOCTYPE html> <html> <head> <?php include 'sources/template/head.php'; ?> <meta http-equiv="Refresh" content="2;url=consultarRedaccion.php" /> </head>
addButton('btn btn-success', 'Submit', 'col-sm-offset-2 col-sm-4', 'Sign Up'); ?> </fieldset> </form> <?php require_once 'Status.php'; require_once 'database.php'; $q = new Status($db); $q->viewStatus('dvd', 'available', 'Return'); ?> <?php require_once "Query.php"; $crud_book = new Query(7, 'dvd', 'item_no,title,genre,description,price,rental_period,status'); $crud_book->mysqlConnect('localhost', 'root', '', 'video_rental'); $crud_book->create(); echo "<hr/>"; $crud_book->read(); echo "<hr/>"; $crud_book->update(); echo "<hr/>"; $crud_book->delete(); echo "<hr/>"; ?> </div> </div> </div> </body> </html>
/** * Метод выполняет дамп таблицы */ public static function dumpTable($idColumn, $table, array $where = array(), $order = null) { //Стартуем секундомер $secundomer = Secundomer::startedInst("Снятие дампа {$table}"); //Отключим ограничение по времени PsUtil::startUnlimitedMode(); //Получим экземпляр логгера $LOGGER = PsLogger::inst(__CLASS__); //Текущий пользователь $userId = AuthManager::getUserIdOrNull(); //Для логов, запросов и все остального $table = strtoupper(PsCheck::tableName($table)); //Макс кол-во записей $limit = PsDefines::getTableDumpPortion(); //Проверим наличие id $idColumn = PsCheck::tableColName($idColumn); $LOGGER->info('Dumping table {}. Id column: {}, limit: {}. User id: {}.', $table, $idColumn, $limit, $userId); //Получаем лок (без ожидания) $lockName = "DUMP table {$table}"; $locked = PsLock::lock($lockName, false); $LOGGER->info('Lock name: {}, locked ? {}.', $lockName, var_export($locked, true)); if (!$locked) { return false; //Не удалось получить лок } $zipDi = false; try { //ЗПРОСЫ: //1. Запрос на извлечение колва записей, подлежащих дампированию $queryCnt = Query::select("count({$idColumn}) as cnt", $table, $where); //2. Запрос на извлечение данных, подлежащих дампированию $queryDump = Query::select('*', $table, $where, null, $order, $limit); //3. Запрос на извлечение кодов дампируемых записей $selectIds = Query::select($idColumn, $table, $where, null, $order, $limit); //4. Запрос на удаление дампированных данных $queryDel = Query::delete($table, Query::plainParam("{$idColumn} in (select {$idColumn} from (" . $selectIds->build($delParams) . ') t )', $delParams)); //Выполним запрос для получения кол-ва записей, подлежащих дампу $cnt = PsCheck::int(array_get_value('cnt', PSDB::getRec($queryCnt, null, true))); $LOGGER->info('Dump recs count allowed: {}.', $cnt); if ($cnt < $limit) { $LOGGER->info('SKIP dumping table, count allowed ({}) < limit ({})...', $cnt, $limit); $LOGGER->info("Query for extract dump records count: {$queryCnt}"); PsLock::unlock($lockName); return false; } //Время дампа $date = PsUtil::fileUniqueTime(false); $time = time(); //Название файлов $zipName = $date . ' ' . $table; //Элемент, указывающий на zip архив $zipDi = DirManager::stuff(null, array(self::DUMPS_TABLE, $table))->getDirItem(null, $zipName, PsConst::EXT_ZIP); $LOGGER->info('Dump to: [{}].', $zipDi->getAbsPath()); if ($zipDi->isFile()) { $LOGGER->info('Dump file exists, skip dumping table...'); PsLock::unlock($lockName); return false; } //Комментарий к таблице $commentToken[] = "Date: {$date}"; $commentToken[] = "Time: {$time}"; $commentToken[] = "Table: {$table}"; $commentToken[] = "Manager: {$userId}"; $commentToken[] = "Recs dumped: {$limit}"; $commentToken[] = "Total allowed: {$cnt}"; $commentToken[] = "Query dump cnt: {$queryCnt}"; $commentToken[] = "Query dump data: {$queryDump}"; $commentToken[] = "Query dump ids: {$selectIds}"; $commentToken[] = "Query del dumped: {$queryDel}"; $comment = implode("\n", $commentToken); //Начинаем zip и сохраняем в него данные $zip = $zipDi->startZip(); $zip->addFromString($zipName, serialize(PSDB::getArray($queryDump))); $zip->setArchiveComment($comment); $zip->close(); $LOGGER->info('Data successfully dumped, zip comment:'); $LOGGER->info("[\n{$comment}\n]"); //Удалим те записи, дамп которых был снят $LOGGER->info('Clearing dumped table records...'); $affected = PSDB::update($queryDel); $LOGGER->info('Rows deleted: {}.', $affected); $LOGGER->info('Dumping is SUCCESSFULLY finished. Total time: {} sec.', $secundomer->stop()->getAverage()); } catch (Exception $ex) { PsLock::unlock($lockName); ExceptionHandler::dumpError($ex); $LOGGER->info('Error occured: {}', $ex->getMessage()); throw $ex; } return $zipDi; }
public function removeResetTokensOfUser($userId) { return Query::delete($this->getDomain()->getTableName(), "userId = :userId", array("userId" => $userId), 100); }
public function deleteCommentsFor($id, $type) { $id = (int) $id; $type = (string) $type; Query::delete('comments')->where('record', $id)->andWhere('type', $type)->act(); }
public static function delete($name) { list($id, $keys) = self::parseName($name); // deleting (locally) if (empty($keys)) { unset(self::$fields[$id]); } else { self::deleteSubKey(self::$fields[$id], $keys); } // pushing changes to database if (!array_key_exists($id, self::$fields)) { // deleting field completely Query::delete('config')->where('name', $id)->act(); self::$noSuchField[$id] = true; } else { // or only updating Query::update('config')->where('name', $id)->set('value', serialize(self::$fields[$id]))->act(); } }
<?php include "sources/funciones.php"; if ($_SESSION["Activa"] and $_SESSION["Tipo_usuario"] == "administrador" and $_GET) { $id = $_GET['id']; require "sources/Query.inc"; $query = new Query(); if ($query->delete("login", "idLogin={$id}")) { $respuesta = ' <img src="images/ok.png" width="100"> <h4> Usuario eliminado correctamente. </h4> '; } else { $respuesta = ' <img src="images/error.png" width="100"> <h4> Ha ocurrido un error. </h4> '; } ?> <!DOCTYPE html> <html> <head> <?php include 'sources/template/head.php'; ?> <meta http-equiv="Refresh" content="2;url=consultarUsuario.php" /> </head>
private function removeOtherTokensOfUser($userId) { Query::delete($this->getDomain()->getTableName(), "userId = :userId", array("userId" => $userId)); }
public function delete() { $query = new Query(); $query->delete($this); }
<?php include "sources/funciones.php"; if ($_SESSION["Activa"] and $_SESSION["Tipo_usuario"] == "administrador" and $_GET) { $id = $_GET['id']; require "sources/Query.inc"; $query = new Query(); if ($query->delete("revisor", "idRevisor={$id}")) { $respuesta = ' <img src="images/ok.png" width="100"> <h4> Revisor eliminado correctamente. </h4> '; } else { $respuesta = ' <img src="images/error.png" width="100"> <h4> Ha ocurrido un error. </h4> '; } ?> <!DOCTYPE html> <html> <head> <?php include 'sources/template/head.php'; ?> <meta http-equiv="Refresh" content="2;url=consultarRevisor.php" /> </head>
/** * Deletes entries from $tableName matching all the conditions in $where * * @param A3gZ\Database\Interfaces\CamlInterface[] $where List of Caml conditions. * @param string $tableName Optional target table's name. If not given $this->tableName is used instead. * * @return A3gZ\Database\AbstractTableDataGateway Self */ public function delete(array $where, $tableName = null) { if (!isset($tableName) && !isset($this->tableName)) { throw new \Exception("Table name is required."); } elseif (!isset($tableName)) { $tableName = $this->tableName; } $qry = Query::delete($tableName); // Inject conditions if (isset($where) && is_array($where)) { foreach ($where as $caml) { $qry->where($caml); } } $qst = $qry->toSql(); if ($this->execute($qst) === false) { return false; } return $this; }