Skip to main content
博客
div+css 博客
javascript 博客
vue 博客
php 博客
微信 博客
php
drupal
composer
thinkphp
onethink
laravel
Swoole
dedecms
magento
smarty
ecshop
zencart
joomla
discuz
wordpress
yii
微信
抖音
ci
weiphp
destoon
python
plone
apache
nginx
cache
memcache
redis
div+css
javascript
jquery
typescript
Vue.js
Amaze
zepto
react
underscore
backbone
angular
lodash
layui
js特效
vbscript
photoshop ai
sql
mysql
mssql
oracle
regular
node.js
腾讯开放平台
dreamweaver
linux
seo
app
asp及asp.net
flash
iis
java
mac
wap
windows
dos
打印机
其它
浏览器
网络
AD域 (exchange)
虚拟机
AC
ai
简写翻译
欢迎各位兄弟 发布技术文章
这里的技术是共享的
个人技术网_前端_后台_php_div_css_linux_javascript_seo
搜索表单
搜索
用户登录
用户名
*
密码
*
重设密码
You are here
首页
thinkphp save()方法
星期五, 2016-06-24 09:23 —
adminshiping1
调用TP的save方法更新数据时,如果新数据与数据库中得数据一致,那么执行M('table')->save(data)方法时,该方法会返回false。
现在的需求是,哪怕用户要更新的数据与原数据一致,也要返回成功,这个功能怎么实现?
云栖大会北京站:
阿里技术专家难得出镜,这次一下来了100多位?!
最佳答案
天使街23号
2015年01月08日
$result = $Recommend->where(array('id' => $id))->save($data);
if(false !== $result || 0 !== $result){
$this->ajaxReturn(array('status' => 'ok', 'info' => '推荐位修改成功'));
}else{
$this->ajaxReturn(array('info' => '推荐位修改失败'));
}
评论(
4
)
相关
□う烟沙
2015年01月08日
我一直用的是"!=" 改成 "!=="这个即可?谢谢各位,
媛子
2015年01月08日
我也遇到过你的这个问题,false !== $result || 0 !== $result 像这种就可以解决啦
ghzz789
2015年01月08日
首先,更新返回的结果是影响行数,返回0或0以上的整数都是更新成功的,只要返回false时才是更新失败,那么只要这样判断即可.
if
(
false
!==
$result
){
//更新成功
}
复制代码
复制代码
复制代码
天使街23号
2015年01月08日
$result = $Recommend->where(array('id' => $id))->save($data);
if(false !== $result || 0 !== $result){
$this->ajaxReturn(array('status' => 'ok', 'info' => '推荐位修改成功'));
}else{
$this->ajaxReturn(array('info' => '推荐位修改失败'));
}
来自
http://www.thinkphp.cn/topic/27136.html
普通分类:
thinkphp