您的位置:首页 > 编程语言 > PHP开发

ThinkPHP,execute和query

2015-11-18 00:00 597 查看
摘要: ThinkPHP,execute和query

// +---------------------------------------------------------------
// | 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'
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息