Return rowid on create record in SQLite3
Hi, When I create a new record in SQLite I need to return the rowid for the new record.
How can I do this?
Many thanks in advance
Check and see if SQLite3 has:
last_insert_id
like mysql does. I'm sure there is documentation like MySql has online documentation.
Edit:
If it does, you need to verify behavior is the same.
$obj = YourModel::create($yourArrayOfAttributes);
$obj->id; // The new row id
@MohamedTammam
$obj->id; doesn’t work with SQLite, the problem is the rowid column is not returned by default unlike mysql which returns the ID as part of the row.
I solved this problem by creating the entry in the database then selecting the last record from the table.
$newRecord = Model::on($this->connection($connection))
->latest('rowid')
->select('rowid', '*')
->first();
return $newRecord;
Please or to participate in this conversation.