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

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