// +---------------------------------------------------------------
// | update o2o_users set gold = (gold + '-1') where user_id = '245'
// +---------------------------------------------------------------
public function updateCount($id,$col,$num = 1){
// 245, gold, 1
$id = (int)$id;
return $this->execute(" update ".$this->getTableName()." set {$col} = ({$col} + '{$num}') where ".$this->pk." = '{$id}' ");
//execute 常用作update和insert,返回影响的行数
//query常用作select,放回影响的数集,array()
//update o2o_users set gold = (gold + '-1') where user_id = '245'
}
ThinkPHP,execute和query
最新推荐文章于 2021-03-21 15:41:53 发布
本文深入探讨了数据库中使用SQL语句进行数据更新的方法,以具体实例展示了如何通过执行更新语句来修改特定记录的属性。重点介绍了如何在PHP环境中执行更新操作,并通过代码示例详细说明了参数化查询的重要性,以防止SQL注入攻击。
5100

被折叠的 条评论
为什么被折叠?



