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

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.

Last SQL Query

Hi guys, i'd searched on forum but there is only old answers, and unreliable ones.

How can I get the last SQL executed on Phalcon 4?

Thanks



8.4k
Accepted
answer

its still the same with phalcon 4

check the API documentaion

check this answer here also


$phql = 'UPDATE `news` SET `category_id` = 5 WHERE `id` = :id';

$this->db->execute($phql, ['id' => 1]);

print_r($this->db->getSQLStatement());

print_r($this->db->getSqlVariables());

News::findFirst();

print_r($this->db->getSQLStatement());

print_r($this->db->getSqlVariables());

and i would recommend checking the class Phalcon\Db\Profiler