We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHQL how to get the parser?

Hello I would Like to use PHQL parser in another project, how can I call it and use it?



16.4k

Can you give more details?

Use the parser to translate the query to sql. is that possible?

edited Mar '15

Yes, when you have installed phalcon extension just create instance from this class, you could make something like this:

<?php

$di = new Phalcon\DI();

//Registrar un servicio 'db'

$di->set('db', function() {
    return new Phalcon\Db\Adapter\Pdo\Mysql(
        "host" => "localhost",
        "username" => "root",
        "password" => "secret",
        "dbname" => "invo"
    );
});

// Instantiate the Query
$query = new Phalcon\Mvc\Model\Query("SELECT * FROM Cars");

// Pass the DI container
$query->setDI($di);

// Execute the query returning a result if any
$cars = $query->execute();

Or simply with php Phalcon\Mvc\Model\Manager() class

ok I do not want to use the PhalconORM for now, but I want to get the phql output to normal sql. I know I have to load the mapping and call out the parser, I just need to know how to use it or how it works and what structure is the map.



3.5k
Accepted
answer

Ok, you can see here how was built it, new phalcon 2.0 version. https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/model/manager.zep, look around here...

I think thats is it, thank you Julian. BTW if I manage to develop a multi connection DataMapper ORM in zephir, would it be interesting for phalcon?