Update transaction BUG and solution of Codeigniter framework, codeigniter framework _ PHP Tutorial

Source: Internet
Author: User
Tags codeigniter
The update transaction BUG and solution of the Codeigniter framework, the codeigniter framework. The update transaction BUG and solution of the Codeigniter framework. the condition of the ci transaction judgment error rollback is that the statement is successfully executed, with regard to the update transaction BUG and solution of the Codeigniter framework, the codeigniter framework

Because the ci transaction determines whether the statement is successfully executed if an error is rolled back, even if the number of affected items is 0 during the update operation, the SQL statement execution result is still 1, the execution is successful, but the number of affected items is 0.

The following describes how to solve this problem:

For a transaction that needs to execute many statements at a time

In the update operation, you only need to determine whether the rollback is performed based on whether the number of affected items is 0. the following assumes that the second statement is an update operation.

The code is as follows:


// Use the manual mode of Codeigniter transactions
$ This-> db-> trans_strict (FALSE );
$ This-> db-> trans_begin ();

$ This-> db-> query ('select... '); // The SELECT operation does not require special processing.
$ This-> db-> query ('Insert... '); // Codeigniter automatically handles INSERT errors.

$ This-> db-> query ('Update ...');
If (! $ This-> db-> affacted_rows () {// roll back if the above UPDATE fails.
$ This-> db-> trans_rollback ();
// @ Todo exception handling
Exit (); // termination or exit is required to prevent the following SQL code from being executed!
}

$ This-> db-> query ('delete ...');
If (! $ This-> db-> affacted_rows () {// roll back if the DELETE operation fails.
$ This-> db-> trans_rollback ();
// @ Todo exception handling
Exit (); // termination or exit is required to prevent the following SQL code from being executed!
}

$ This-> db-> query ('select... '); // The SELECT operation does not require special processing.
$ This-> db-> query ('Insert... '); // Codeigniter automatically handles INSERT errors.

If ($ this-> db-> trans_status () === TRUE ){
$ This-> db-> trans_commit ();
} Else {
$ This-> db-> trans_rollback ();
// @ Todo exception handling
}

If not many statements are executed at a time, you can make a final judgment to decide the rollback.

If there is no update operation in the statement, you can use automatic transactions.


How many concurrent users can access the codeigniter framework?

The number of concurrent jobs has a major relationship with the server architecture, but program optimization also has a lot to do with it, such as how the cache application is like. Of course, it has nothing to do with the framework.

For php CodeIgniter framework

I just read the CodeIgniter manual yesterday. in the CodeIgniter URLs chapter, there are instructions:

You can add rules to the. htaccess file as follows:

RewriteEngine on

RewriteCond $1! ^ (Index \. php | images | robots \. txt)

RewriteRule ^ (. *) $/index. php/$1 [L]

Transcoding (transaction) BUG and solution: codeigniter framework determines whether the statement is successfully rolled back due to ci transactions...

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.