<?php include 'inc.php'; $autoload = (require __DIR__ . '/../src/Autoload.php'); $autoload->register(); use Oppa\Database; use Oppa\Config; use Oppa\Query\Builder as QueryBuilder; $cfg = ['agent' => 'mysqli', 'profiling' => true, 'database' => ['fetch_type' => 'object', 'charset' => 'utf8', 'timezone' => '+00:00', 'host' => 'localhost', 'name' => 'test', 'username' => 'test', 'password' => '********']]; $db = new Database($cfg); $db->connect(); $qb = new QueryBuilder($db->getLink()); $qb->setTable('users'); // $qb->select('id,name'); // $qb->select('id,name')->where('id=?', [1]); // $qb->select('id,name')->where('id=?', [1])->limit(1); // $qb->select('id,name')->whereLike('name LIKE ?', ['%Ker"em%']); // $qb->select('id,name')->whereLike('(id LIKE ? OR name LIKE ?)', ['2%', '%Ke_rem%']); // $qb->select('id,name') // ->where('id=?', [1]) // ->where('(name=? OR name=? OR old BETWEEN %d AND %d)', ['Kerem', 'Murat', 30, 40], $qb::OP_AND) // ; // $qb->select()->aggregate('count'); // pre($qb->get()); $qb->setTable('users u'); $qb->select('u.*, us.score, ul.login')->aggregate('sum', 'us.score', 'sum_score')->join('users_score us', 'us.user_id = u.id')->joinLeft('users_login ul', 'ul.user_id = u.id')->whereIn('u.id', [1, 2, 3])->whereBetween('u.old', [30, 50])->whereNotNull('ul.login')->groupBy('u.id')->orderBy('old')->having('sum_score <= ?', [30])->limit(0, 10); pre($qb->toString()); pre($qb->get()); // pre($qb->getAll()); // pre($qb->execute()); // insert
/** * Count. * @param string $params * @param array $paramsParams * @return int */ public final function count(string $params = null, array $paramsParams = null) : int { $query = new QueryBuilder($this->getDatabase()->getLink()); $query->setTable($this->table); if (!empty($params) && !empty($paramsParams)) { $query->where($params, $paramsParams); } return $query->count(); }
/** * New query builder. * @param string|null $stack * @return Oppa\Query\Builder */ public final function queryBuilder(string $stack = null) : QueryBuilder { $queryBuilder = new QueryBuilder(); $queryBuilder->setLink($this->db->getLink()); // use self name if ($stack == '') { $stack = $this->stack; } $queryBuilder->setTable($stack); return $queryBuilder; }