updateByPk() method
public integer updateByPk(mixed $pk, array $attributes, mixed $condition='', array $params=array ( ))
| ||
$pk | mixed | primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). |
$attributes | array | list of attributes (name=>$value) to be updated |
$condition | mixed | query condition or criteria. |
$params | array | parameters to be bound to an SQL statement. |
{return} | integer | the number of rows being updated |
Source Code: framework/db/ar/CActiveRecord.php#1678 (show)
Updates records with the specified primary key(s). See find() for detailed explanation about $condition and $params. Note, the attributes are not checked for safety and validation is NOT performed.
-----------------------------------------------------------------------
Update By Primary Key User::model()->updateByPk($model->id,array("username"=>'jerome'))
-----------------------------------------------------------------------
Source Code: framework/db/ar/CActiveRecord.php#1678 (hide)public function updateByPk($pk,$attributes,$condition='',$params=array()) { Yii::trace(get_class($this).'.updateByPk()','system.db.ar.CActiveRecord'); $builder=$this->getCommandBuilder(); $table=$this->getTableSchema(); $criteria=$builder->createPkCriteria($table,$pk,$condition,$params); $command=$builder->createUpdateCommand($table,$attributes,$criteria); return $command->execute(); }
No comments:
Post a Comment