createCommand()->update怎么用and加多一个条件 [ 未指定版本 ]
$sql->createCommand()->update('table',$arr,'uid= :name',[':name'=>$id])->execute();
实际生成
UPDATE
table SET
state=1 WHERE uid= '1000020'
想实现
UPDATE
table SET
state=1 WHERE uid= '1000020' and time=20181107
createCommand()->update 该怎么写。看过手册了,没有具体的范例,
共 4 个回答
-
你可以看看这篇文章:https://www.cnblogs.com/liangzia/p/5937378.html 希望有所帮助!!!
共 1 条回复 -
/** * @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
,共 1 条回复 -
这个简单的很,一看就是一个懒家伙,文档说得那么详细了都不看一遍。至少应该在【数据库访问】部分看一遍再提问吧?
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条件用关联数组就行。
小伙子以后花几分钟看看所有文档有关数据库部分,你会发现好多。
共 5 条回复 -
开门_查水表
注册时间:2018-09-28
最后登录:2018-11-14
在线时长:6小时2分
最后登录:2018-11-14
在线时长:6小时2分
- 粉丝0
- 金钱115
- 威望0
- 积分175