55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Класс оболочка для PDOStatement для замены Creole
|
|
*/
|
|
class Database_Statement
|
|
{
|
|
protected $limit = null;
|
|
protected $offset = null;
|
|
protected $statement = null;
|
|
protected $binds = array();
|
|
protected $conn;
|
|
protected $query;
|
|
|
|
function __construct($query, /*.Database.*/ $conn) {
|
|
$this->query = $query;
|
|
$this->conn = $conn;
|
|
}
|
|
|
|
function setInt($n, $value) {
|
|
$this->binds [] = array($n, $value, PDO::PARAM_INT);
|
|
}
|
|
|
|
function setString($n, $value) {
|
|
$this->binds [] = array($n, $value, PDO::PARAM_STR);
|
|
}
|
|
|
|
function setBlob($n, $value) {
|
|
$this->binds [] = array($n, $value, PDO::PARAM_LOB);
|
|
}
|
|
|
|
function setLimit($limit) {
|
|
$this->limit = $limit;
|
|
}
|
|
|
|
function setOffset($offset) {
|
|
$this->offset = $offset;
|
|
}
|
|
|
|
function executeQuery() {
|
|
if ($this->limit) {
|
|
$this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}";
|
|
}
|
|
/*.Database_PDOStatement.*/$stmt = $this->conn->prepare($this->query);
|
|
foreach ($this->binds as $bind) {
|
|
list($n, $value, $type) = $bind;
|
|
$stmt->bindValue($n, $value, (int) $type);
|
|
}
|
|
|
|
$stmt->execute();
|
|
$stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return $stmt;
|
|
}
|
|
}
|