Yii framework builder, update, and delete usage

Source: Internet
Author: User
This article describes how to use the yii framework builder, update, and delete. For more information, see

This article describes how to use the yii framework builder, update, and delete. For more information, see

The query builder provided by Yii is still very useful, saving the SQL spelling process. Today, when I write a statement, I encountered such a problem.

The Code is as follows:


$ Connection = Yii: app ()-> db;
$ Command = $ connection-> createCommand ();
$ Operate_rst = 0;
If (! Empty ($ _ POST ['lid']) {
$ Operate_rst = $ command-> update ('emg _ landing ', $ landing_info, 'lid =: lid', array (': lid' => $ _ POST ['lid']);
}
Else {
$ Operate_rst = $ command-> insert ('emg _ landing', $ landing_info );
}
$ Connection-> active = false;
If ($ operate_rst> 0 ){
Functions: returnOk ('OK! ');
}
Functions: returnErrorJson ();

$ Operate_rst is used to record the operation results. It is no problem to execute the new insert statement. However, during the update process, the operation may fail to be displayed. After checking for half a day, the cause cannot be found, so I have to go through the document.

# Update-detail

Which of the following statements about return is:

The Code is as follows:


{Return} integer number of rows affected by the execution.

I understand the problem in an instant, because sometimes the data is not changed but the update operation is triggered. Therefore, when the number of rows being changed is 0, the returned judgment enters the error code ..

Similarly, the return values of the delete () and insert () methods also indicate the number of affected rows. Therefore, the delete and insert methods can determine whether the operation is successful based on whether the return values are greater than 0, however, the update operation is not necessarily successful. If the returned value is 0, the database operation may be successful.

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.