I simplify my problem into a simple status.
mysql> select * from `table`;
+--------+---------+
| f1 | f2 |
+--------+---------+
| hallo | welcome |
| string | array |
+--------+---------+
2 rows in set (0.00 sec)
I want to change the table into the following result.
mysql> select * from `table`;
+--------+------- --+
| f1 | f2 |
+--------+---------+
| hallo | welcomehaha |
| string | arrayhaha |
+--------+------- --+
2 rows in set (0.00 sec)
Here is my code.
<?php
header("Content-Type: text/html; charset=gbk");
$db=new PDO("mysql:host=localhost;dbname=test","root","");
$statement1=$db->prepare("select f1,f2 from `table`");
$statement1 -> execute();
while($row=$statement1->fetch()){
$new_content=$row["f1"];
$new_f2=$row['f2'].'haha';
echo $new_f2.'</br>';
$statement2=$db->prepare("update `table` set f2=$new_f2 where f1={$row['f1']}");
$statement2 -> execute();
}
?>
The output is:
welcomehaha
arrayhaha
The value of f2
isn't changed, why isn't the update 'table' set f2=$new_f2 where f1={$row['f1']}
being executed?