Yii MySQL modifies database data

WBOY
Release: 2016-07-29 09:11:47
Original
1492 people have browsed it

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>?>
Copy after login

//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>?>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template