53 lines
1.0 KiB
PHP
53 lines
1.0 KiB
PHP
<?php
|
|
|
|
class Query
|
|
{
|
|
// SQL Query parts
|
|
public $fields = ' * ';
|
|
public $from = '';
|
|
public $where = ' 1 ';
|
|
public $order = '';
|
|
public $group = '';
|
|
public $having = '';
|
|
public $limit = '';
|
|
|
|
// Bound parameters
|
|
public $data = [];
|
|
public $types = [];
|
|
|
|
public function getQuery()
|
|
{
|
|
$query = "SELECT {$this->fields}\nFROM {$this->from}\nWHERE {$this->where}";
|
|
|
|
if ($this->group) {
|
|
$query .= "\nGROUP BY {$this->group}";
|
|
}
|
|
|
|
if ($this->order) {
|
|
$query .= "\nORDER BY {$this->order}";
|
|
}
|
|
|
|
if ($this->having) {
|
|
$query .= "\nHAVING {$this->having}";
|
|
}
|
|
|
|
if ($this->limit) {
|
|
$query .= "\nLIMIT {$this->limit}";
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$query = $this->getQuery();
|
|
|
|
return sqlQuery($query, $this->data, $this->types);
|
|
}
|
|
|
|
public function addData($data)
|
|
{
|
|
$this->data = array_merge($this->data, $data);
|
|
}
|
|
}
|