I ran into a strange bug in my PHP web app that I'm unable to sort out. The php script fetches a row from the database, it processes it and serializes a new query and writes back the row to the database.
I copied the code that does this:
foreach($a as $key => $value)
{
$a[$key]="'".mysql_real_escape_string($value)."'";
}
$a['lastUpdate']="$when";
//assembling request
$assignments=array();
foreach($a as $key => $value)
{
$assignments[]="$key=$value";
}
$q="UPDATE wtfb2_villages SET ".implode(',',$assignments)." WHERE (id=${a['id']})";
logText($q);
logText(mysql_error());
$r=mysql_query($q) or die(__FILE__.':'.__LINE__.':'.mysql_error().':'.$q);
logText(mysql_affected_rows());
logText('Mysql error in query is: '.mysql_error()."\n");
That UPDATE seemingly executes. mysql_error() gives an empty string. mysql_affected_rows says 1 just like when everything is done. But if I look into the table using phpmyadmin I saw that nothing is changed.
I logged the query itself its:
UPDATE wtfb2_villages SET id='22',ownerId='56',villageName='Új falu',x='0',y='1',buildPoints='7.2226273148149',barracksLevel='0',archeryRangeLevel='0',stablesLevel='0',workshopLevel='0',townHallLevel='0',blacksmithLevel='0',goldmineLevel='1',wallLevel='0',spearmen='0',archers='0',knights='0',catapults='0',diplomats='0',spearmanLevel='0',archerLevel='0',knightLevel='0',catapultLevel='0',spearmenTraining='0',archersTraining='0',knightsTraining='0',catapultsTraining='0',diplomatsTraining='0',lastUpdate='2011-01-18 21:56:10' WHERE (id='22')
If I just copy-paste this query directly into the phpmyadmin it executes it and I see the result in the table.
The table is using myIsam engine. So no transactions or anythin such.
I got stuck at this problem more than 2 hours and I'm unable to find out what's going on.
This is the only one query that does this. queries before and after this one executing properly.
Any ideas?