Codeigniter transactions - trans_start trans_complete trans_status
Just trying to figure out why counterfeiters' transactions are not behaving the way I expected.
This trans_status () transaction of TRANS SUCCESS triggers :
$this->db->trans_start();
$this->db->query("UPDATE `TABLE1` SET `NAME` = 'AAA' WHERE `ID` = '1'");
$this->db->query("UPDATE `TABLE2` SET `NAME` = 'BBB' WHERE `ID` = '2'");
$this->db->trans_complete();
if($this->db->trans_status() === FALSE){// Check if transaction result successful
echo "<BR>------- TRANS FAILED -------</BR>";
}else{
echo "<BR>------- TRANS SUCCESS -------</BR>";
}
TABLE1 is updated with AAA "and TABLE2 is updated with < BBB
This transaction trans_status () reports " TRANS FAILED ", as expected, because the column " nepravilnyyID " not > exist in TABLE2 :
$this->db->trans_start();
$this->db->query("UPDATE `TABLE1` SET `NAME` = 'AAA' WHERE `ID` = '1'");
$this->db->query("UPDATE `TABLE2` SET `NAME` = 'BBB' WHERE `incorrectID` = '2'");
$this->db->trans_complete();
if($this->db->trans_status() === FALSE){// Check if transaction result successful
echo "<BR>------- TRANS FAILED -------</BR>";
}else{
echo "<BR>------- TRANS SUCCESS -------</BR>";
}
TABLE1 IS NOT updated with AAA "and TABLE2 IS NOT updated with < BBB
However, these trans_status () transactions report " TRANS SUCCESS ", although there is no ID with the value 55 ' TABLE2 ?!?!:
$this->db->trans_start();
$this->db->query("UPDATE `TABLE1` SET `NAME` = 'AAA' WHERE `ID` = '1'");
$this->db->query("UPDATE `TABLE2` SET `NAME` = 'BBB' WHERE `ID` = '55'");
$this->db->trans_complete();
if($this->db->trans_status() === FALSE){// Check if transaction result successful
echo "<BR>------- TRANS FAILED -------</BR>";
}else{
echo "<BR>------- TRANS SUCCESS -------</BR>";
}
TABLE 1 MUST be updated with AAA "and TABLE2 is NOT . Updated since NO ID 55 on TABLE2 - but I expect it to rollback because TABLE2 UPDATE will not succeed.
What gives? I thought the idea behind a transaction is that everything between trans_start () and trans_complete () must be successful for the entire transaction to succeed. Otherwise, the entire transaction is rolled back .
I tried this with SET and UPDATE and had the same problem. The first db-> query () will commit and save changes, leaving the second db-> query () unexecuted and trans_status () reporting it as success
What am I missing here?
Thanks everyone :)
Sincerely.
source to share
What transactions are looking for successful requests. Your request
$this->db->query("SELECT * FROM TABLE2 WHERE ID = 55");
is a valid query and is executed accordingly and returns 0 rows. Not returning rows does not mean that the query has not run.
If you provide your example for update requests it might shed some light on this question.
source to share
Use this procedure. It works somehow ^ _ ^
$this->db->trans_start();
$this->db->query("UPDATE `TABLE1` SET `NAME` = 'AAA' WHERE `ID` = '1'");
$this->db->query("UPDATE `TABLE2` SET `NAME` = 'BBB' WHERE `ID` = '2'");
if($this->db->trans_status() === FALSE){// Check if transaction result successful
$this->db->trans_rollback();
echo "<BR>------- TRANS FAILED -------</BR>";
}else{
$this->db->trans_complete();
echo "<BR>------- TRANS SUCCESS -------</BR>";
}
source to share