1.数据库字段值为null利用setInc方法无法直接写入,先判断是否为空,再写入。
if($points->add($dataList)){
$user=M('cuser');
$null=$user->where(array('id'=>$userid))->field('points')->find();
//if(empty($null['points'])){ //判断数据库字段是否为null 不支持0
if(is_null($null['points'])){
$user->where(array('id'=>$userid))->save($data);
}else{
$user->where(array('id'=>$log))->setInc('points',5);
}
$status=1;
}
2.*********************楼下评论**********************************
<?php
$null="0";
if(empty($null)){
echo 1;
}else{
echo 2;
}
输出1,说明0也为null 用is_null.上面错误改正!
3.
<?php
$null="0";
if(is_null($null)){
echo 1;
}else{
echo 2;
}
echo 2;