At 11:10 -0400 10/13/04, Michael Ragsdale wrote:I've been using mysql_insert_id() with great success, but now I've got a problem. I'm using UPDATE to, well, update a record in a database and according to the docs...
mysql_insert_id() is updated after INSERT and UPDATE statements that generate an AUTO_INCREMENT value or that set a column value to LAST_INSERT_ID(expr).
If the record did not exist and UPDATE performed as INSERT, then I would theoretically have no problem.
That condition doesn't apply, because UPDATE never performs an INSERT.
DOH! Sorry, I was thinking REPLACE, not UPDATE.
Hower, since the record that I'm updating already exists, the AUTO_INCREMENT value also already exists and that value is not being re-generated. Therefore, the value that mysql_insert_id() is returning is zero. Is there a similar way to capture the id of the record that is being updated?
Not in the way you suggest. However, if you're updating a single record, I would think that you're doing so on the basis of some primary key that you specify in WHERE clause. If the primary key is your AUTO_INCREMENT column, then you already know the value you want. If it's not your AUTO_INCREMENT column, you can use it in a select to retrieve the AUTO_INCREMENT column.
Yes, I am actually using a two-column key, but it is not the AUTO_INCREMENT column. I realize I can execute another SELECT to get that column, but was hoping for something similar to $sth->{'mysql_insertid'} that may have been more optimal. I guess not.
Thanks anyway.
-Mike
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]