Here is my code structure:
// db connection here
try {
$dbh_conn->beginTransaction();
$stm = $dbh_conn->prepare("SELECT user_id FROM resend_pass WHERE token = ?");
$stm->execute(array('value'));
$num_rows = $stm->fetch(PDO::FETCH_ASSOC);
if($num_rows) {
echo 'one'; die;
} else {
echo 'two'; die;
}
$dbh_conn->commit();
} catch(PDOException $e) {
$dbh_conn->rollBack();
echo 'three'; die;
}
When exactly that query executes? You know, my script works exactly as expected. But I'm wonder how? As you see there is an if - else
statement before commite()
; Also both if
and else
have die;
in their blocks. So as far as I know, this line never executes:
$dbh_conn->commit();
Because there is surly a die
before it. But surprisingly my code works as well. Here is all possible outputs:
- It prints
one
ifvalue
exists as a token in theresend_pass
table. - It prints
two
ifvalue
doesn't exist as a token in theresend_pass
table. - It prints
three
if there is an error (like syntax SQL error)
See? All fine. But how? When exactly commit()
function executes? Before those die
s ?
Note: The engine of resend_pass
is innoDB.