Heim > Artikel > Backend-Entwicklung > Yii MySQL修改数据库的数据,yiimysql修改数据库_PHP教程
<?<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>?>
//第二种方法
<?<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>?>