Home > Backend Development > PHP Tutorial > mysql - thinkphp更新成功的完美的判断方法?

mysql - thinkphp更新成功的完美的判断方法?

WBOY
Release: 2016-06-06 20:42:06
Original
1281 people have browsed it

下面哪种比较全面

<code>$result=$m->where($w)->save($data);
</code>
Copy after login
Copy after login

第一种:

<code>if(false !== $result){
//成功
echo '2';
}else{
//更新失败
echo '0';
}   
</code>
Copy after login
Copy after login

第二种:

<code>if ($result>0 || $result ===0) {
//
echo"1";
}else{
//
echo"0";
}
</code>
Copy after login
Copy after login

回复内容:

下面哪种比较全面

<code>$result=$m->where($w)->save($data);
</code>
Copy after login
Copy after login

第一种:

<code>if(false !== $result){
//成功
echo '2';
}else{
//更新失败
echo '0';
}   
</code>
Copy after login
Copy after login

第二种:

<code>if ($result>0 || $result ===0) {
//
echo"1";
}else{
//
echo"0";
}
</code>
Copy after login
Copy after login

更新数据分为两种情况:

1.更新成功。返回影响行数。如果数据没有变动则返回 0
2.更新失败。返回 false
所以判断可以使用

<code>if($result ! == false ){
    //成功
}
</code>
Copy after login

就可以了。

tp model 里 false等于失败

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template