zoukankan      html  css  js  c++  java
  • CakePHP更新数据(转载)

      CakePHP中更新数据的方法包括saveField()和updateAll()两种,其中前者用于保存单个字段,后者用于更新多条记录。

      saveField(string $fieldName, string $fieldValue, $validate = false)

      saveField()在调用前需要设置模型的ID($this->ModelName->id = $id)。使用该方法时,$fieldName应该只包含字段名,而不是模型名加字段名。

      例如,使用saveField更新投稿日志的标题:

    $this->Post->saveField('title', 'A New Title for a New Day');

      updateAll(array $fields, array $conditions)

      updateAll()将被更新的记录用$conditions数组定义,字段的值会按照$fields的定义进行更新。

      例如,对建立时间超过1年的成员进行确认,可能使用如下的更新语句:

    $this_year = date('Y-m-d h:i:s', strtotime('-1 year'));
    $this->Baker->updateAll(
        array('Baker.approved' => true),
        array('Baker.created <=' => "$this_year")
    );

      $fields>数据接收SQL表达式。文本数据需要手动地添加引号。

      例如,更改特定用户的票的状态:

    $this->Ticket->updateAll(
        array('Ticket.status' => "'closed'"),
        array('Ticket.customer_id' => 453)
    );
  • 相关阅读:
    word2vec
    视频推荐系统
    python基础
    go-elasticsearch
    Docker 部署 go项目
    gohbase
    禅道部署linux
    jmeter 报错 Error occurred during initialization of VM Could not reserve enough space for object heap
    jarvis OJ-DSA
    算法-我的第一本算法书(一)
  • 原文地址:https://www.cnblogs.com/pallee/p/4078207.html
Copyright © 2011-2022 走看看