Wednesday, August 22, 2012

UpdateByPk Yii


updateByPk() method
public integer updateByPk(mixed $pk, array $attributes, mixed $condition='', array $params=array ( ))
$pkmixedprimary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
$attributesarraylist of attributes (name=>$value) to be updated
$conditionmixedquery condition or criteria.
$paramsarrayparameters to be bound to an SQL statement.
{return}integerthe number of rows being updated
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

About

Blogger templates