无法更新mysql中的值

zqdjd7g9  于 2021-06-17  发布在  Mysql
关注(0)|答案(2)|浏览(225)

我有一张table config_table 带字段 id , config_value . 我想更新一下 config value 如下所示: id ='6' ```
if($user->status_id=='1' && $user->reviewed!='0'){
if($sl_flag==0 && $requestor_role->role_id==7){
$status="Waiting for Review";
$title="Waiting for Review";
}elseif($sl_flag==0){
$status="Waiting for dept.owner approval";
$title="Waiting for Deptment owner approval ";
}else{
$status="Waiting for prac.owner approval";
$title="Waiting for practice owner approval";
}
}

我已更新为

update config_table set config_value=' if($user->status_id=='1' && $user->reviewed!='0'){
if($sl_flag==0 && $requestor_role->role_id==7){
$status="Waiting for Review";
$title="Waiting for Review";
}elseif($sl_flag==0){
$status="Waiting for dept.owner approval";
$title="Waiting for Deptment owner approval ";
}else{
$status="Waiting for prac.owner approval";
$title="Waiting for practice owner approval";
}
}' where id='6';

我在putty服务器上尝试过这个方法,但是在}附近的每一行中我都发现了语法错误
rryofs0p

rryofs0p1#

你用的是 ''config_value 你也是从哪里开始的 '' . 所以它认为它到此为止,但你只想赋值。这段代码中有几个选项可以修复它。首先:php是松散类型的,所以您可以只更新 ''config_value"" .

update config_table set config_value='     if($user->status_id=="1" && $user->reviewed!="0"){
 if($sl_flag==0 && $requestor_role->role_id==7)
 { $status="Waiting for Review"; 
 $title="Waiting for Review";
 } 
 elseif($sl_flag==0)
 { $status="Waiting for dept.owner approval";
 $title="Waiting for Deptment owner approval ";
 }
 else
 { $status="Waiting for prac.owner approval";
 $title="Waiting for practice owner approval";
 }
}' where id="6";

另一个选项是转义使用 '' . 这可以通过添加 \' . value = 'if($user->status_id==\'1\') { /*your code*/ }'

cigdeys3

cigdeys32#

尝试使用如下addslashes:

$value = <<< END
     if($user->status_id=='1' && $user->reviewed!='0'){
    if($sl_flag==0 && $requestor_role->role_id==7){ 
        $status="Waiting for Review"; 
        $title="Waiting for Review";
    }elseif($sl_flag==0){ 
        $status="Waiting for dept.owner approval";
        $title="Waiting for Deptment owner approval ";
    }else{ 
        $status="Waiting for prac.owner approval";
        $title="Waiting for practice owner approval";
    }
    }
END;

    update config_table set config_value=$value where id='6';

相关问题