Looking for feedback on the way I am updating rows
Posted: Tue Mar 24, 2009 9:21 pm
Hello,
As far as performance does it matter which way I do this?
I have an array of ID's (could be around 20-50) that I pass to a function to UPDATE each ROW in a TABLE of that ID.
I am using ADODB and thought it would be best to do something like this:
However, although it is a simple update it seems to be unreliable. (I am doing this through AJAX, if it matters.)
So, I removed the transaction stuff and just started doing it this way:
It seems to be more reliable, however, now I fear that I may be slamming my database too much by hitting it with updates in the for loop.
Is this a bad thing to do? Should I be worried about this or is this a normal thing? Or is there a better way?
Thanks!!
As far as performance does it matter which way I do this?
I have an array of ID's (could be around 20-50) that I pass to a function to UPDATE each ROW in a TABLE of that ID.
I am using ADODB and thought it would be best to do something like this:
Code: Select all
$DB->StartTrans();
for ($i = 0; $i < count($theIdList); $i++) {
$this->database->Execute("UPDATE mytable SET val1 = $i WHERE id = $theIdList[$i]");
}
$DB->CompleteTrans();So, I removed the transaction stuff and just started doing it this way:
Code: Select all
for ($i = 0; $i < count($theIdList); $i++) {
$this->database->Execute("UPDATE mytable SET val1 = $i WHERE id = $theIdList[$i]");
}Is this a bad thing to do? Should I be worried about this or is this a normal thing? Or is there a better way?
Thanks!!