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

How can i get lastInserId (PHQL)?

Currently I'm using PHQL. How can I get lastInsertId() in this case?

Some part of code in my Controller:

            $status = $this->modelsManager->executeQuery(
            "INSERT INTO Project\Models\Posts (fields) VALUES (values)",
            [
               params
            ]);

            if ($status->success()) {

            print_r($status->lastInsertedId());

            } 


6.0k
Accepted
answer

Hi, assuming your column with id in your DB is called 'id', this code should do the trick:

<?php
$status->getModel()->id;