Get SQL Query String with condition & bind parameter.

Hi,

I am new in phalcon. I am trying to debug SQL Query string but I am unable to find out how i can do it ??

Can you help me plz.

Ex: Users::find('isactive="1"') I want query like : "Select * from users where isactive='1'";

In Laravel I can do it by using ->getSql() but in phalcon how i cn do it??

Thanks .

edited Apr '16

https://docs.phalconphp.com/en/latest/reference/phql.html https://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Query%5Builder.html

From query builder you can call

// Returns a PHQL statement built based on the builder parameters
$phql = $builder->getPhql();

// Returns the query built
$query = $builder->getQuery();

Find method are returning direct results, you cant get query from it. You can do it if you implement events manager for DB adapter

https://docs.phalconphp.com/en/latest/reference/events.html

Hi , Thank you for reply , but I don't want to do with "modelsManager".

I have some relation in model , and on the basic of that realtion I want to know the exact query is running to get result .

and some where i have join query. and want to debug ...

https://docs.phalconphp.com/en/latest/reference/phql.html https://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Query%5Builder.html

From query builder you can call

```php // Returns a PHQL statement built based on the builder parameters $phql = $builder->getPhql();

// Returns the query built $query = $builder->getQuery(); ```

Find method are returning direct results, you cant get query from it. You can do it if you implement events manager for DB adapter

https://docs.phalconphp.com/en/latest/reference/events.html

I've found the easiest solution is to simply turn on the general query log in Mysql, then do a tail -f /path/to/log/file. That way it doesn't matter how the query is built, you can see the actual text of the query that MySQL sees.