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.
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.
I suppose another way to do this would be to add ai_col=LAST_INSERT_ID(ai_col)
to the SET clause of your UPDATE statement.
--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]