We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

update and delete not showing any error message if the id is not found in db

Update and delete query are not showing any error if the id is not found in db , its showing success in both cases if id found or not found, queries are working fine but not showing any error of id not found

 $phql = "DELETE FROM TaskqueApi\Models\Uploads WHERE iduploads='$upload_id'";
$status = $this->modelsManager->executeQuery($phql);

 if ($status->success() == true) {
    $response['message'] = "Attachment Deleted Successfully";
} else {
    $response = array();
    foreach ($status->getMessages() as $message) {
        $response['message'] = $message->getMessage();
    }
}

its work fine with insert query but issues with delete and update as i mentioned above



58.4k

I don't see echo or print messages ?

$status array is empty for this

any response for this ?



98.9k

It's not supposed to show an error if it did no find records to update or delete. This situation is very common to throw an exception there. Imagine if MySQL worked like that:

Current:

mysql> update robots set name = 'Some' where id > 100;
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0  Changed: 0  Warnings: 0

What you expect:

mysql> update robots set name = 'Some' where id > 100;
ERROR 1054 (42S22): No records to update were found

but its always true if id is found or not found

I want to use this $this->modelsManager->affectedRows(); but its not working here ,the query is successful whether id is found or not found.