Yii deletebyattributs usage, careful use of DAO's delete_php tutorial

Source: Internet
Author: User
This article to give your classmates about Yii deletebyattributs usage, cautious use of DAO Delete, I hope this article will be helpful to everyone.

Yii framework must be careful to use the DAO delete, accidentally it can not be conditions, it becomes the whole table delete.

Can be used ActiveRecord deletebyattributes or DeleteAll method is relatively not easy to write wrong.

Deletebyattributes usage is as follows:

The code is as follows Copy Code

Myclass::model ()->deleteallbyattributes (Array (
' Phone_number ' = $phoneNumber,
));

Or the first argument is empty, use the second condition argument

The code is as follows Copy Code

Myclass::model ()->deleteallbyattributes (Array (), ' phone_number ' =:p hone_number ', Array (
':p hone_number ' = $phoneNumber,
));

or use DeleteAll ():

The code is as follows Copy Code

Myclass::model ()->deleteall (' phone_number ' =:p hone_number ', Array (
':p hone_number ' = $phoneNumber,
));

Another one with an in condition.

copy code

$condition = new Cdbcriteria ();
$condition->addcondition (' status=:status ');
$condition->params = Array (': Status ' =>1);
$condition->addincondition (' user_id ', Array (100111,100221,100221));
User::model ()->deleteall ($condition);D An example of an AO band in condition


Yii::app ()->db->createcommand ()
->delete (' Mw_user ', Array (' and ', ' user_id=:user_id ', Array (' In ', ' position_id ', array (+/-)), Array (': user_id ' =>121111));

However, please use the DAO's delete carefully, when your condition is wrong, it will not be able to generate a where condition, while the SQL statement also does not have where, but not necessarily error, the result is no where delete, the result is the whole table is deleted.

http://www.bkjia.com/PHPjc/633167.html www.bkjia.com true http://www.bkjia.com/PHPjc/633167.html techarticle This article to give your classmates about Yii deletebyattributs usage, cautious use of DAO Delete, I hope this article will be helpful to everyone. Yii framework must be cautious with the DAO Delete, accidentally ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.