PHP MySQLi and MySQLi_STMT: Which insert_id to use?

Posted by Carvell Fenton on Stack Overflow See other posts from Stack Overflow or by Carvell Fenton
Published on 2010-04-06T18:00:52Z Indexed on 2010/04/06 18:03 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

Hello all,

Both the MySQLi and MySQLi_STMT classes have an $insert_id property.

If I am connected to my database using a MySQLi object (say $db), and then I perform an INSERT with a MySQLi_STMT object (say $stmt), to get the id of the last INSERT, should I use:

$last_id = $db->insert_id;

or

$last_id = $stmt->insert_id;

Or would they be the same, in which case it doesn't matter?

I thought this might be a quick answer for someone, and save me the time of writing the test code to check it.

Thanks in advance as always.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysqli