[ciapug] mysqli prepared statements

Scott Phillips scott.phillips at DRAKE.EDU
Mon Dec 12 16:12:22 CST 2005


I think the resounding silence following your question can be translated 
into, "No. We don't know."

Regarding your current approach... Do you lock the table before the insert 
and unlock it after you select the max id? Otherwise, another record could 
be inserted between the two and you'll end up with the wrong id. That's how 
I do it, anyway. Is there a better way?



At 10:26 AM 12/10/2005 -0600, you wrote:
>Does anyone know if you can use the mysqli->insert_id inside a prepared
>statement to get the id of the record that has just been inserted?
>
>I'm doing it with a select statement which uses the same parameters as the
>insert statement and selects "MAX(id) AS id" as the output parameter.  It
>works, but it's easy to make an error when typing it in.
>
>Carl
>http://www.carl-olsen.com/
>
>_______________________________________________
>ciapug mailing list
>ciapug at cialug.org
>http://cialug.org/mailman/listinfo/ciapug



More information about the ciapug mailing list