Welcome Guest, Not a member yet? Register   Sign In
Detecting an error in updating a record where the record is not existed using PHP MYSQL PDO
#1

[eluser]Unknown[/eluser]
I have been developing programs using XAMPP (PHP MYSQL Apache in Windows) with PDO.
Just to test if the record is happened to be deleted before updating at the very last moment, by other user. (I inquired the existence just before submitting "update", and yet the record is deleted after that.)
I expected PDO to retun me 0 record affected (when I tested it straight into MySQL on command screen, it returned 0 record), however PDO returned me 1 record, of course the record is not existed in the table after this execution.

I prepared SQL statement and bind the parameter of key info as following:

$objStmt = $db->prepare($strSQL);
$objStmt->bindParam(1, $this->adl_address_code);
$intResult = $objStmt->execute();
if ($intResult > 0) {
echo "ok:" . $this->adl_address_code; }
else {
echo "error:" . $this->adl_address_code; }

How can I detect error of updating non-existing record?




Theme © iAndrew 2016 - Forum software by © MyBB