Home > Backend Development > PHP Tutorial > Codeigniter framework update transaction (transaction) BUG and solution, codeigniter framework_PHP tutorial

Codeigniter framework update transaction (transaction) BUG and solution, codeigniter framework_PHP tutorial

WBOY
Release: 2016-07-13 10:22:12
Original
1209 people have browsed it

Codeigniter framework update transaction (transaction) BUG and solution, codeigniter framework

Since the CI transaction judgment error rollback condition is whether the statement is executed successfully, and during the update operation, even if the number of items affected is 0, the result of the SQL statement execution is still 1, because it was executed successfully, and only the affected items are 1. The number of items is 0.

Here’s how to solve this problem:

For transactions that need to execute many statements at one time

You only need to decide whether to roll based on whether the number of affected items is 0 during the update operation. It is assumed below that the second statement is an update operation.

Copy code The code is as follows:

//Adopt manual mode of Codeigniter transaction
$this->db->trans_strict(FALSE);
$this->db->trans_begin();
                             
$this->db->query('SELECT ...');//SELECT operation requires no special processing
$this->db->query('INSERT ...');//If an INSERT error occurs, Codeigniter will automatically handle it
                             
$this->db->query('UPDATE ...');
If (!$this->db->affacted_rows()) {//If the above UPDATE fails, rollback
           $this->db->trans_rollback();
​​​​ //@todo exception handling part
exit();//Need to terminate or exit to prevent the following SQL code from continuing to execute!
}
                             
$this->db->query('DELETE ...');
If (!$this->db->affacted_rows()) {//If the above DELETE fails, rollback
$this->db->trans_rollback();
​​​​ //@todo exception handling part
Exit();//Need to terminate or exit to prevent the following SQL code from continuing to execute!
}
                             
$this->db->query('SELECT ...');//SELECT operation requires no special processing
$this->db->query('INSERT ...');//If an INSERT error occurs, Codeigniter will automatically handle it
                             
If ($this->db->trans_status() === TRUE) {
           $this->db->trans_commit();
} else {
           $this->db->trans_rollback();
​​​​ //@todo exception handling part
}

If there are not many statements executed at one time, you can make a judgment at the end to decide to roll back

If there is no update operation in the statement, automatic transactions can be used.

How many people can the codeigniter framework support accessing at the same time?

The number of concurrency is mainly related to the server architecture, but the optimization of the program also has a lot to do with it, such as how well the cache is used. Of course it has nothing to do with the framework

For php CodeIgniter framework

I just read the CodeIgniter manual yesterday, and the method is explained in the CodeIgniter URLs chapter:

It is processed by adding rules in the .htaccess file, as follows

RewriteEngine on

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/848801.htmlTechArticleCodeigniter framework update transaction (transaction) BUG and solution, codeigniter framework due to ci transaction judgment error rollback conditions It is whether the statement is executed successfully, and when updating, it...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template