for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Divergence\IO\Database\Query;
class Select extends AbstractQuery
{
public ?string $where;
public ?string $having;
public ?string $limit;
public ?string $order;
public string $expression = '*';
public bool $calcFoundRows = false;
public function expression(string $expression): Select
$this->expression = $expression;
return $this;
}
public function where(string $where): Select
$this->where = $where;
public function having(string $having): Select
$this->having = $having;
public function limit(string $limit): Select
if (!empty($limit)) {
$this->limit = $limit;
public function order(string $order): Select
if (!empty($order)) {
$this->order = $order;
public function calcFoundRows(): Select
$this->calcFoundRows = true;
public function __toString(): string
$expression = ($this->calcFoundRows ? 'SQL_CALC_FOUND_ROWS ' : '') . $this->expression;
if (isset($this->tableAlias)) {
$from = sprintf('`%s` AS `%s`', $this->table, $this->tableAlias);
} else {
$from = sprintf('`%s`', $this->table);
$limit = isset($this->limit) ? ' LIMIT '.$this->limit : '';
$where = isset($this->where) ? ' WHERE ('.$this->where.')' : '';
$having = isset($this->having) ? ' HAVING ('.$this->having.')' : '';
$order = isset($this->order) ? ' ORDER BY '.$this->order : '';
return sprintf('SELECT %s FROM %s %s %s %s %s', $expression, $from, $where, $having, $order, $limit);