Home Backend Development PHP Tutorial Yii deleteByAttributs usage, use Dao's delete_PHP tutorial with caution

Yii deleteByAttributs usage, use Dao's delete_PHP tutorial with caution

Jul 13, 2016 am 10:43 AM
dao delete yii introduce about classmate article usage of

This article will introduce to you the usage of Yii deleteByAttributs. Use Dao's delete with caution. I hope this article will be helpful to everyone.

Yii framework must use Dao's delete with caution. If it accidentally fails to generate the conditions, it will become a complete table deletion.

You can use ActiveRecord’s deleteByAttributes or deleteAll methods which are relatively easy to write incorrectly.

The usage of deleteByAttributes is as follows:

The code is as follows
 代码如下 复制代码

MyClass::model()->deleteAllByAttributes(array(
    'phone_number'=>$phoneNumber,
));

Copy code

 代码如下 复制代码

MyClass::model()->deleteAllByAttributes(array(),'`phone_number` = :phone_number',array(
    ':phone_number'=>$phoneNumber,
));

MyClass::model()->deleteAllByAttributes(array(
'phone_number'=>$phoneNumber,
));

 代码如下 复制代码

MyClass::model()->deleteAll('`phone_number` = :phone_number',array(
    ':phone_number'=>$phoneNumber,
));

or if the first parameter is empty, use the second conditional parameter
 代码如下 复制代码

$condition = new CDbCriteria();
$condition->addCondition('status=:status');
$condition->params = array(':status'=>1);
$condition->addInCondition('user_id',array(100111,100221,100221));
User::model()->deleteAll($condition);Dao带in条件的示例


Yii::app()->db->createCommand()
->delete('mw_user', array('and', 'user_id=:user_id', array('in', 'position_id', array(1,2,3))),array(':user_id'=>121111));

MyClass::model()->deleteAllByAttributes(array(),'`phone_number` = :phone_number',array(
':phone_number'=>$phoneNumber,
));
The code is as follows

Copy code

The code is as follows Copy code
MyClass::model()->deleteAll('`phone_number` = :phone_number',array(
':phone_number'=>$phoneNumber,
)); Another one with in condition
The code is as follows 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);Dao example with in condition

Yii::app()->db->createCommand()
->delete('mw_user', array('and', 'user_id=:user_id', array('in', 'position_id', array(1,2,3))),array(':user_id'= >121111)); But please use DAO's delete with caution. If you write the conditions wrong, it will not be able to generate the where condition. At the same time, there is no where in the sql statement, but it does not necessarily report an error. The result will be delete without where. The result will be that the entire table is deleted. http://www.bkjia.com/PHPjc/633167.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633167.htmlTechArticleThis article will introduce to you the usage of Yii deleteByAttributs. Use Dao delete with caution. I hope this article will be helpful to everyone. Helps. The Yii framework must use Dao's delete with caution. If you are not careful...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1240
24
Analyze the usage and classification of JSP comments Analyze the usage and classification of JSP comments Feb 01, 2024 am 08:01 AM

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

Usage of WPSdatedif function Usage of WPSdatedif function Feb 20, 2024 pm 10:27 PM

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.

How to correctly use the exit function in C language How to correctly use the exit function in C language Feb 18, 2024 pm 03:40 PM

How to use the exit function in C language requires specific code examples. In C language, we often need to terminate the execution of the program early in the program, or exit the program under certain conditions. C language provides the exit() function to implement this function. This article will introduce the usage of exit() function and provide corresponding code examples. The exit() function is a standard library function in C language and is included in the header file. Its function is to terminate the execution of the program, and can take an integer

Detailed explanation and usage introduction of MySQL ISNULL function Detailed explanation and usage introduction of MySQL ISNULL function Mar 01, 2024 pm 05:24 PM

The ISNULL() function in MySQL is a function used to determine whether a specified expression or column is NULL. It returns a Boolean value, 1 if the expression is NULL, 0 otherwise. The ISNULL() function can be used in the SELECT statement or for conditional judgment in the WHERE clause. 1. The basic syntax of the ISNULL() function: ISNULL(expression) where expression is the expression to determine whether it is NULL or

What is Dogecoin What is Dogecoin Apr 01, 2024 pm 04:46 PM

Dogecoin is a cryptocurrency created based on Internet memes, with no fixed supply cap, fast transaction times, low transaction fees, and a large meme community. Uses include small transactions, tips, and charitable donations. However, its unlimited supply, market volatility, and status as a joke coin also bring risks and concerns. What is Dogecoin? Dogecoin is a cryptocurrency created based on internet memes and jokes. Origin and History: Dogecoin was created in December 2013 by two software engineers, Billy Markus and Jackson Palmer. Inspired by the then-popular "Doge" meme, a comical photo featuring a Shiba Inu with broken English. Features and Benefits: Unlimited Supply: Unlike other cryptocurrencies such as Bitcoin

Use CSS Transform to transform elements Use CSS Transform to transform elements Feb 24, 2024 am 10:09 AM

Usage of Transform in CSS The Transform property of CSS is a very powerful tool that can perform operations such as translation, rotation, scaling and tilting of HTML elements. It can dramatically change the appearance of elements and make web pages more creative and dynamic. In this article, we will introduce the various uses of Transform in detail and provide specific code examples. 1. Translate (Translate) Translate refers to moving an element a specified distance along the x-axis and y-axis. Its syntax is as follows: tran

PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions Feb 25, 2024 am 11:15 AM

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

See all articles