<?php
/**
* Location db\mysql\query.php
*/
namespace DB\Mysql;
use DB\Mysql as mysql;
class Query extends mysql {
private $resource_id;
private $record_set;
function __construct($sql) {
global $DB_SETTINGS;
$this->record_set = Array();
$this->resource_id = parent::__construct($DB_SETTINGS);
$this->query($sql);
}
public function query($sql) {
$this->resource_id = mysqli_query($this->connection, $sql);
if (!$this->resource_id) {
echo (mysql_error());
return null;
}
return $this;
}
public function fetch() {
$record_set = Array();
while ($row = mysqli_fetch_assoc($this->resource_id)) {
$record_set[] = $row;
}
return $record_set;
}
/** other utility functions **/
public function first() {
mysqli_data_seek($this->resource_id, 0);
$record_set = Array();
$row = mysqli_fetch_assoc($this->resource_id);
if ($row) {
$record_set = $row;
}
return $record_set;
}
public function last() {
mysqli_data_seek($this->resource_id, 0);
$record_set = Array();
while ($row = mysqli_fetch_assoc($this->resource_id)) {
$record_set = $row;
}
return $record_set;
}
}
?>