Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Query builder for raw SQL (without models)


Aug '15

Feb '16

2

2107

2


tmihalik
2.2k
edited Jan '16
Aug '15

Query builder for raw SQL

https://github.com/tmihalik/phtuning-php/blob/master/Library/Phalcon/Db/Query/Builder.php

Using with simple tables (without models):

$query = new \Phalcon\Db\Query\Builder;
$query->columns('name')
    ->from('robots')
    ->andWhere('age > :age:')
    ->orderBy('name, id');
$result = $query->execute(['age' => 18]);
$result->setFetchMode(\Phalcon\Db::FETCH_ASSOC);

while ($row = $result->fetch()) {
  echo $row['name'];
}

Using with stored procedures:

$query = new \Phalcon\Db\Query\Builder;
$query->columns('name')
    ->from('getrobotsbyage(:age:)')
    ->orderBy('name, id');
$result = $query->execute(['age' => 18]);
$result->setFetchMode(\Phalcon\Db::FETCH_ASSOC);

while ($row = $result->fetch()) {
  echo $row['name'];
}

nejtr0n
90
Accepted
answer

insert / update / delete does not support?