The latest learning Yii framework, sharing some learning experience, suitable for beginners, experts please press ctrl + w
//The first method
<?<span>php </span><span>/*</span><span> * $id 代表主键,可以是一个也可以是一个集合。 * $attributes 代表是要修改的字段的集合。 * $condition 代表条件。 * $params 传入的值。 </span><span>*/</span><span>$count</span> = Model::model()->updateByPk(<span>$id</span>,<span>$attributes</span>,<span>$condition</span>,<span>$params</span><span>); </span><span>if</span>(<span>$count</span> > 0<span>) { </span><span>echo</span> '修改成功'<span>; } </span><span>else</span><span> { </span><span>echo</span> '修改失败'<span>; } </span>?>
//The second method
<?<span>php </span><span>$model</span> = Model::model()->findByPk(<span>$id</span><span>); </span><span>$model</span>->username = 'yiistudy'<span>; </span><span>$model</span>->password = 'mysql'<span>; </span><span>$count</span> = <span>$model</span>->update(<span>array</span>('username','password'<span>)); </span><span>if</span>(<span>$count</span>>0<span>) { </span><span>echo</span> '修改成功'<span>; } </span><span>else</span><span> { </span><span>echo</span> '修改失败'<span>; } </span>?>
The above introduces Yii MySQL to modify the data of the database, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.