开门_查水表
- 开门_查水表 2018-11-08 已签到连续签到4天,获得了20个金钱
这个简单的很,一看就是一个懒家伙,文档说得那么详细了都不看一遍。至少应该在【数据库访问】部分看一遍再提问吧?
https://www.yiichina.com/doc/api/2.0/yii-db-command#update()-detail另外还有一个更快捷的办法,在AR(ActiveRecord)里。如下: public static function updateAll($attributes, $condition = '', $params = []) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } 其中第二个参数$condition可以是字符串,也可以是关联数组。你的and条件用关联数组就行。
小伙子以后花几分钟看看所有文档有关数据库部分,你会发现好多。
摸了半天,原来和select的where一毛样的用法,
[ 'and', 'uid=:id', 'num=:time' ], [ ':id' => $id, ':time' => $time ]```
这个简单的很,一看就是一个懒家伙,文档说得那么详细了都不看一遍。至少应该在【数据库访问】部分看一遍再提问吧?
https://www.yiichina.com/doc/api/2.0/yii-db-command#update()-detail另外还有一个更快捷的办法,在AR(ActiveRecord)里。如下: public static function updateAll($attributes, $condition = '', $params = []) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } 其中第二个参数$condition可以是字符串,也可以是关联数组。你的and条件用关联数组就行。
小伙子以后花几分钟看看所有文档有关数据库部分,你会发现好多。
哈哈!~我有点生气了啊!
这个简单的很,一看就是一个懒家伙,文档说得那么详细了都不看一遍。至少应该在【数据库访问】部分看一遍再提问吧?
https://www.yiichina.com/doc/api/2.0/yii-db-command#update()-detail另外还有一个更快捷的办法,在AR(ActiveRecord)里。如下: public static function updateAll($attributes, $condition = '', $params = []) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } 其中第二个参数$condition可以是字符串,也可以是关联数组。你的and条件用关联数组就行。
小伙子以后花几分钟看看所有文档有关数据库部分,你会发现好多。
晕哦,不是吧,条件直接用数组啊,我记得我当时把前面中括号括起来 ,直接报错了⊙︿⊙
- 开门_查水表 2018-11-07 已签到连续签到3天,获得了15个金钱
这个简单的很,一看就是一个懒家伙,文档说得那么详细了都不看一遍。至少应该在【数据库访问】部分看一遍再提问吧?
https://www.yiichina.com/doc/api/2.0/yii-db-command#update()-detail另外还有一个更快捷的办法,在AR(ActiveRecord)里。如下: public static function updateAll($attributes, $condition = '', $params = []) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } 其中第二个参数$condition可以是字符串,也可以是关联数组。你的and条件用关联数组就行。
小伙子以后花几分钟看看所有文档有关数据库部分,你会发现好多。
谢谢大叔@刘师傅
$minAge = 30; createCommand()->update('user',$arr, 'age > :minAge', [':minAge' => $minAge])->execute(); createCommand()->update('table',$arr,'uid= :name',[':name'=>$id])->execute();
好像还是一样的
这样不行把
$aaa=['and', 'id=1', 'id=2'] ;
update('table',$arr,$aaa)/** * @param string $table the table to be updated. * @param array $columns the column data (name => value) to be updated. * @param string|array $condition the condition that will be put in the WHERE part. Please * refer to [[Query::where()]] on how to specify condition. * @param array $params the parameters to be bound to the command * @return $this the command object itself */ public function update($table, $columns, $condition = '', $params = []) { $sql = $this->db->getQueryBuilder()->update($table, $columns, $condition, $params); return $this->setSql($sql)->bindValues($params); }
condition
:@param string|array $condition the condition that will be put in the WHERE part. Please
,小学生看不懂e文