note 79753 deleted from function.mysql-query by felipe

From: Date: Sat, 15 Dec 2007 15:33:21 +0000
Subject: note 79753 deleted from function.mysql-query by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133575@lists.php.net to get a copy of this message
Note Submitter: phpawe at aweawe dot cjb dot net ---- It's a shame that multiple queries are not supported but the only case I see that presents a problem is when one wants to UPDATE different rows of one table with different values. For SELECT, INSERT and DELETE statements you can simply manipulate the query string to your likings and send a single query. As I understand, this is also the fastest way to handle SQL since you let the engine do the optimization. Example: Don't use INSERT INTO my_table (id, text) VALUES (123,'kushkush'); INSERT INTO my_table (id, text) VALUES (321,'mushmush'); but: INSERT INTO my_table (id, text) VALUES (123,'kushkush'),(321,'mushmush'); Now regarding UPDATE queries of multiple rows: UPDATE my_table SET text='bipbip' WHERE id='123' LIMIT 1; UPDATE my_table SET text='beep' WHERE id='456' LIMIT 1; there's the CASE statement you should check out: UPDATE my_table SET text=CASE id WHEN 123 THEN 'bipbip' WHEN 456 THEN 'beep' ELSE 'ERR!!!' END WHERE id='123' OR id='456' but this becomes quite awkward when the value of the field depends on more then a single field (hint: you can use CONCAT). So I hope this helps you all and let me know if there's a better way for the UPDATE scenario I mentioned.

« previous php.notes (#133575) next »