note 79753 added to function.mysql-query

From: Date: Tue, 11 Dec 2007 13:30:31 +0000
Subject: note 79753 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-133363@lists.php.net to get a copy of this message
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. ---- Server IP: 212.199.163.191 Probable Submitter: 89.1.14.43 (proxied: 89.1.14.43) ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/79753 Del: integrated -- https://master.php.net/note/delete/79753/integrated Del: useless -- https://master.php.net/note/delete/79753/useless Del: bad code -- https://master.php.net/note/delete/79753/bad+code Del: spam -- https://master.php.net/note/delete/79753/spam Del: non-english -- https://master.php.net/note/delete/79753/non-english Del: in docs -- https://master.php.net/note/delete/79753/in+docs Del: other reasons-- https://master.php.net/note/delete/79753 Reject -- https://master.php.net/note/reject/79753 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133363) next »