One big query vs. lots of small queries
| From: | Jeffrey | Date: | Mon, 18 Dec 2006 14:23:36 +0000 |
| Subject: | One big query vs. lots of small queries | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-42825@lists.php.net to get a copy of this message | ||
Here's a question of efficiency.
I have an application in PHP using MySQL.
Users select items on a form and each selected item represents a change in a table row. It is possible that 100s of changes might be chosen from a single form.
Which is likely to be faster/more efficient?
multiple queries like...
$query="UPDATE some_table SET x='$y' WHERE id='$z[$key]'";
$result=mysql_query($query);
or one huge query like...
$query="UPDATE some_table SET x='$y' WHERE id='$z[$key]'
OR id='$z[$another_key]' OR id='$z[$another_key]
OR id='$z[$another_key]"; etc?
$result=mysql_query($query);
In the latter, PHP would have to construct the WHERE string, which would require some processing power as well. Is there a limit to how many OR's can be added to a mysql query? No - don't answer that, I'll look in the manual.
Many thanks,
Jeff