Scalr\Model\AbstractEntity::_delete PHP Méthode

_delete() private méthode

Removes records from database by criteria
private _delete ( array $criteria = null, integer $limit = null ) : integer
$criteria array optional The search criteria.
$limit integer optional The records limit
Résultat integer Returns number of affected rows
    private function _delete(array $criteria = null, $limit = null)
    {
        if (is_array($criteria) && array_key_exists(static::STMT_FROM, $criteria)) {
            $stmtFrom = "FROM " . $criteria[static::STMT_FROM];
            unset($criteria[static::STMT_FROM]);
        } else {
            $stmtFrom = "FROM {$this->table()}";
        }
        if (is_array($criteria) && array_key_exists(static::STMT_WHERE, $criteria)) {
            $stmtWhere = "WHERE " . $criteria[static::STMT_WHERE];
            $rawWhere = !empty($criteria[static::STMT_WHERE]);
            unset($criteria[static::STMT_WHERE]);
        } else {
            $stmtWhere = "WHERE";
        }
        if (!empty($criteria)) {
            $built = $this->_buildQuery($criteria);
        }
        $builtWhere = !empty($built['where']) ? $built['where'] : '';
        $stmt = "\n            DELETE {$stmtFrom}\n            {$stmtWhere} " . (!empty($rawWhere) ? "AND (" . $builtWhere . ")" : $builtWhere) . "\n            " . (isset($limit) ? "LIMIT " . intval($limit) : "") . "\n        ";
        $this->db()->Execute($stmt);
        return $this->db()->_affectedrows();
    }