Example #1
0
 /**
  * 执行更新
  * @param array $update 键值对数组
  * @return int 影响的行数;
  */
 protected final function update(array $update)
 {
     foreach ($update as $key => $val) {
         if (preg_match('/([+|\\-|\\*|\\/|%|&|\\||\\!|\\^])(\\d+)/', $val, $result)) {
             // 自增等系列处理
             $set = "`{$key}`=`{$key}`{$result[1]}:{$key}";
             $val = $result[2];
         } else {
             // 默认处理方式
             $set = "`{$key}`=:{$key}";
         }
         $sets[] = $set;
         $this->sql['values'][":{$key}"] = $val;
     }
     // set语句
     $sets = implode(',', $sets);
     // sql语句
     $sql = "UPDATE {$this->table} SET {$sets} {$this->sql['where']} {$this->sql['order']} {$this->sql['limit']}";
     // 执行sql语句
     $this->db->query($sql, $this->sql['values']);
     // 清空数据
     $this->resetSql();
     // 返回当前对象
     return $this->db->rowCount();
 }