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.

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());

            }


4.2k
Accepted
answer

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

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