This article mainly introduces how to use yii Framework builder, update, and delete. if you need it, you can refer to the query builder provided by Yii, which is still very useful, saving you from the SQL spelling process, this problem occurs when I write a statement today.
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.
Http://www.yiiframework.com/doc/api/1.1/CDbCommand#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.