|
Posted by Chung Leong on 10/24/06 04:36
Daz wrote:
> The problem is that when I have a few hundred results to compare.
> Should I really query the database that many times? Could I do it with
> a single query, and if so, how would I know what items the user already
> owns a particular item, and update the database using the PHP-MySQL
> layer. To my understanding, you can't execute and UPDATE or INSERT
> statement from within a SELECT statement. Nor can you execute several
> statements, such as multiple UPDATE statements or several INSERT
> statements all in 1.
No, that still wouldn't remove the race condition. What you want to do
is put a unique constraint on the table, then have your script just
perform the INSERT. If it fails, then you know you have a duplicate.
MySQL also support the INSERT ... ON DUPLICATE KEY UPDATE syntax I
believe.
Navigation:
[Reply to this message]
|