CodeIgniter Framework update transaction (transaction) bug and workaround, CodeIgniter framework _php Tutorial

Source: Internet
Author: User
Tags codeigniter

CodeIgniter Framework update transaction (transaction) bug and workaround, CodeIgniter framework


Because the CI transaction judged that the condition of the rollback was that the statement was successful, while the update operation, even if the affected number of bars was executed by the 0,sql statement, the result is still 1 because it succeeds, only the number of bars affected is 0.

Here's how to solve this problem:

For a transaction that executes many statements at a time

Just under the update operation, depending on whether the number of bars affected is zero or not, it is assumed that the second statement is an update operation.

Copy CodeThe code is as follows:
Manual mode with CodeIgniter transactions
$this->db->trans_strict (FALSE);
$this->db->trans_begin ();

$this->db->query (' SELECT ... ');//select operation without special handling
$this->db->query (' INSERT ... ')//insert error will be codeigniter automatic processing

$this->db->query (' UPDATE ... ');
if (! $this->db->affacted_rows ()) {//UPDATE above fails to rollback
$this->db->trans_rollback ();
@todo Exception Handling Section
Exit ();//need to stop or jump out to avoid the following SQL code to continue execution!
}

$this->db->query (' DELETE ... ');
if (! $this->db->affacted_rows ()) {//DELETE above fails to rollback
$this->db->trans_rollback ();
@todo Exception Handling Section
Exit ();//need to stop or jump out to avoid the following SQL code to continue execution!
}

$this->db->query (' SELECT ... ');//select operation without special handling
$this->db->query (' INSERT ... ')//insert error will be codeigniter automatic processing

if ($this->db->trans_status () = = = TRUE) {
$this->db->trans_commit ();
} else {
$this->db->trans_rollback ();
@todo Exception Handling Section
}

If there are not many statements executed at one time, you can determine the rollback by making a final decision.

If there is no update operation in the statement, the automatic transaction is available.


CodeIgniter Framework supports simultaneous access to many people

Concurrency has a major relationship to the server architecture, but the optimization of the program also has a lot to do with, such as how the cache is applied. Of course it doesn't have much to do with frames.

For PHP CodeIgniter Framework

Yesterday just read the CodeIgniter Handbook, in CodeIgniter URLs This chapter has the description method:

This is done by adding rules to the. htaccess file, as follows

Rewriteengine on

Rewritecond $!^ (index\.php|images|robots\.txt)

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

http://www.bkjia.com/PHPjc/848801.html www.bkjia.com true http://www.bkjia.com/PHPjc/848801.html techarticle CodeIgniter Framework Update transaction (transaction) Bug and resolution, CodeIgniter framework because the CI transaction judgment error rollback condition is that the statement is executed successfully, while the update operation, ...

  • 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.