我有一个表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';
我已经在腻子服务器中尝试过此操作,但是每行的}附近语法都出现错误。如何更新此
答案 0 :(得分:1)
您正在''
中使用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*/ }'
答案 1 :(得分:0)
尝试使用类似这样的加号:
$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';