QueryBuilder


Description

Complicated queries sometimes mean building a lot of extremely similar queries. What if it was possible to build parts of a query in a convenient way? Introduce Query Builder mysql.

WywołanieNazwa
MySQL query prepareQuery()
bind parms from whereChunk prepareWhere()
MySQL order by prepareOrder()
MySQL groupBy prepareGroupBy()
MySQL limit prepareLimit()
MySQL array parms prepareParms()
build MySQL query getQuery()
get MySQL bind parms getParams()

prepareQuery($sql, $parms = [])

The basic method for building queries.

$query = $db->prepareQuery('SELECT * FROM users');

prepareWhere($parms = [])

A method used for filtering queries.

$where = [new WhereChunk('user_id = ?', ['1'])];
$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareWhere($where);

You can use it for simpler queries with defined data and filters.

prepareOrder($orderBy, $sort)

A method used for sorting.

$where = [new WhereChunk('active > ?', ['1'])];
$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareWhere($where);
$query->prepareOrder('username', 'ASC');

prepareGroupBy($groupBy)

Groups the query

$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareGroupBy('firstname');

prepareLimit($limit, $offset)

Useful method for limiting appendix data when using the pagination.

$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareLimit('10', '30');

prepareParms($parms = [])

Binds the parameter to the query.

$query = $db->prepareQuery('SELECT * FROM users WHERE id = ?');
$query->prepareParms(['1']);

getQuery()

Builds the mysql query.

$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareOrder('username', 'ASC');
$prepareQuery = $query->getQuery();

getParams()

Collects the parameters for binding.

$where = [new WhereChunk('active > ?', ['1']]);
$query = $db->prepareQuery('SELECT * FROM users');
$query->prepareWhere($where);
$query->prepareOrder('username', 'ASC');

$prepareQuery = $query->getQuery();
$bindQuery = $query->getParams();
Edit page (QueryBuilder)