Welcome Guest, Not a member yet? Register   Sign In
Transactions and AffectedRows
#1

(This post was last modified: 04-15-2020, 05:24 AM by stlake2011.)

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




Theme © iAndrew 2016 - Forum software by © MyBB