first commit
This commit is contained in:
52
class/class.Query.php
Normal file
52
class/class.Query.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user