Exemple #1
0
 /**
  * 使字段的值<b>减少</b>指定的数值[值一般是数字,默认为 1]
  * @access public
  * @param string $fieldName 字段名称 可以是一个数组,例:array('pcount' => 1, 'acount' => 2)
  * @param int $value 减少的值
  * @return mixed
  */
 public function filedAutoLessen($fieldName, $value = 1)
 {
     $this->_checkWhere();
     $this->_allotDatabaseServer('UPDATE');
     $this->_db_drive_connect->showQuery($this->_show_query);
     $sql = '';
     if (is_array($fieldName)) {
         foreach ($fieldName as $key => $val) {
             if ($sql != '') {
                 $sql .= ',';
             }
             $sql .= '`' . $key . '`=`' . $key . '`-' . XF_Db_Tool::escape($val);
         }
         $sql = 'UPDATE `' . $this->_db_name . '`.`' . $this->_db_table->getTableName() . '` SET ' . $sql . ' ' . $this->_adv_where;
     } else {
         $sql = 'UPDATE `' . $this->_db_name . '`.`' . $this->_db_table->getTableName() . '` SET `' . $fieldName . '`=`' . $fieldName . '`-' . XF_Db_Tool::escape($value) . ' ' . $this->_adv_where;
     }
     $result = $this->_db_drive_connect->execute($sql);
     $this->_clearProperty();
     return $result;
 }
Exemple #2
0
 /**
  * 更新数据
  * @param string $table 数据表名称
  * @param array $data 数据组
  * @param string $where 条件
  * @return mixed
  */
 public function update($table, array $data, $where)
 {
     $set = array();
     foreach ($data as $key => $val) {
         //过滤非标量
         if (is_scalar($val)) {
             if ($val === '$NULL') {
                 $set[] = '`' . $key . "`= NULL";
             } elseif (strpos($val, '$PK') === 0) {
                 $val = substr($val, 3);
                 $set[] = '`' . $key . "`={$val}";
             } else {
                 $set[] = '`' . $key . "`='" . XF_Db_Tool::escape($val) . "'";
             }
         }
     }
     if (empty($set)) {
         return false;
     }
     $query = 'UPDATE `' . $this->_db_name . '`.`' . $table . '` SET ' . implode(',', $set) . ' ' . $where;
     return $this->execute($query);
 }