• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transactions and AffectedRows

#1
Morning all,

Quick question for yall.

When I am running a DB transaction, if it all goes smoothly (as reported by the transaction) I want to do a secondary check (yes I am paranoid on this front), of my own with affectedRows() but its always returning 0 whether the result of the query(ies) themselves were successful or not.

Is this by design and I should just rely on what the transaction reports and bypass the affectedRows() function altogether?  

Extremely oversimplified example:

PHP Code:
$sql1 "INSERT INTO tbl1(id,field1) VALUES(?,?);

$this->db->transStart();
$this->db->query($sql1);
$this->db->transComplete();

if(
$this->db->transStatus() === FALSE) {
    return 
$result = [
        'status' => FALSE,
        'message' => 'One or both queries failed'
    ];
} else {
    if(
$this->db->affectedRows() != 1) {
        return 
$result = [
            'status' => FALSE,
            'message' => 'Nothing Inserted'
        ];
    } else {
        return 
$result = [
            'status' => TRUE,
            'message' => 'Inserted'
        ];
    }


The false result array in the affectedRows seems to always return on success or not.
Should I try a manual transaction or would that return the same as the automatic transaction above?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.