PHP MySQL Weird Update Problem
Posted
by Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2010-03-31T09:09:44Z
Indexed on
2010/03/31
9:13 UTC
Read the original article
Hit count: 281
I have a heap based table in MySQL that I am trying to update via PHP, but for some reason, the updates do not seem to be taking place.
Here is my test code:
<?php
$freepoints[] = 1;
$freepoints[] = 2;
$freepoints[] = 3;
foreach ($freepoints as $entrypoint) {
$query = "update gates set lane='{$entrypoint}' where traffic > 50 limit 50";
echo "$query\n";
mysql_query($query);
echo mysql_affected_rows()."\n";
}
?>
This outputs the following:
update gates set lane='1' where traffic > 50 limit 50
50
update gates set lane='2' where traffic > 50 limit 50
50
update gates set lane='3' where traffic > 50 limit 50
50
In the database to start with lanes 1/2/3 had 0 records and lanes 4/5/6 had 100 records. From this I am expecting all 6 lanes to now have 50 records each. However when I look lanes 4/5/6 still have 100 records and 1/2/3 still have 0 records.
When I copy the query "update gates set lane='1' where traffic > 50 limit 50" into phpMyAdmin it works absolutely fine, so any ideas why it isn't working in my PHP script when mysql_affected_rows is saying it has updated 50 records?
© Stack Overflow or respective owner