Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么update命令可以';不能被处决吗?_Php_Mysql_Sql Update - Fatal编程技术网

Php 为什么update命令可以';不能被处决吗?

Php 为什么update命令可以';不能被处决吗?,php,mysql,sql-update,Php,Mysql,Sql Update,我把我的问题简化成一个简单的状态 mysql> select * from `table`; +--------+---------+ | f1 | f2 | +--------+---------+ | hallo | welcome | | string | array | +--------+---------+ 2 rows in set (0.00 sec) 我想将表更改为以下结果 mysql> select * from `table`; +--

我把我的问题简化成一个简单的状态

mysql> select * from `table`;
+--------+---------+
| f1     | f2      |
+--------+---------+
| hallo  | welcome |
| string | array   |
+--------+---------+
2 rows in set (0.00 sec)
我想将表更改为以下结果

mysql> select * from `table`;
+--------+-------    --+
| f1     | f2          |
+--------+---------+
| hallo  | welcomehaha |
| string | arrayhaha   |
+--------+-------    --+
2 rows in set (0.00 sec)
这是我的密码

<?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();
    }    
?>

f2
的值没有更改,为什么
更新“表”设置f2=$new\u f2其中f1={$row['f1']}
正在执行?

您必须在单引号“”之间输入值,因为它是文本,可能是这样的

$statement2=$db->prepare("update  `table` set f2='$new_f2' where f1='{$row['f1']}'");

因为,你没有引用你的价值观;它们是弦。另外,您没有检查错误。
…设置f2=123haha
。。。您的表格中是否有
123haha
字段?请提供更多解释以帮助op理解,而不仅仅是给他答案。
$statement2=$db->prepare("update  `table` set f2='$new_f2' where f1='{$row['f1']}'");
$statement2=$db->prepare("update `table` set `f2`=concat(`f2`,'haha');");