Hello everyone I'm trying to use phalcon without ORM. I want to separate business logic and data access with DataMapper pattern and I can't find how I can build queries without raw SQL, but using original phalcon queryBuilder.
Is there any chance to do it?
Is this what you are looking for?
<?php
//Getting a whole set
$robots = $this->modelsManager->createBuilder()
->from('Robots')
->join('RobotsParts')
->orderBy('Robots.name')
->getQuery()
->execute();
//Getting the first row
$robots = $this->modelsManager->createBuilder()
->from('Robots')
->join('RobotsParts')
->orderBy('Robots.name')
->getQuery()
->getSingleResult();
From Phalcon docs: Phalcon Query Language (PHQL)
I figured out how to do it I'm using phalcon with doctrine DBAL it's working great for me
I found 2 ways solve it if i'm not mistaken.
Solution 1#
use Phalcon\Mvc\Model\Query\Builder;
$result = $this->modelsManager->createBuilder()
->columns("table1.f1, table1.f2,table2.f3,table2.f4")
->From('table1')
->innerjoin('table2', 'table1.matchfield = table2.matchfield')
->where("table1.fieldname = '$value' ")
->getQuery()
->execute();
Solution 2#
$res = $this->db->execute("UPDATE Tablename SET field1= ?,field2=?,field3=? WHERE id = ?",array($field1,$field2,$field3,$id));