We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Mysql Query not working

this query not working in my phalcon project but it execute in mysql very well.

$query="SELECT distinct ats.status_id, astat.value FROM ActivityTypeStatus ats, ActivityStatus astat where ats.type_id IN(1,4,2) and ats.status_id = astat.status_id"; $activity_status = $this->modelsManager->createQuery($query); $rows = $activity_status->execute();

edited Mar '14

"modelsManager->createQuery" accepts only PHQL https://docs.phalcon.io/en/latest/reference/phql.html

But PHQL has some restrictions for now... try to use "AS" statement in "FROM ActivityTypeStatus AS ats, ActivityStatus AS astat".

And also it is possible some problems with DISTINCT https://github.com/phalcon/cphalcon/issues/1631 (with Postgresal).

edited Mar '14

If you want to use PDO you can just call get your DB intsance from your bootstrap where you set it in the DI:0

    $di->set('db', function() {
          $database = new Phalcon\Db\Adapter\Pdo\Mysql([ /** Your Config Here **/]);
          return $database;

To get the instance from any location in Phalcon use:

    $di = Phalcon\DI::getDefault();
    $db = $di->get('db');

Then you can call:

    $result = $db->execute("Your string");