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 record with raw SQL and PHQL doen't work

Hi, I have this simple function that makes a simple update to a record. For an unknown reason, it does not update the record. Nothing happens, no error, just the update is not done. What may be the problem? I tried with PHQL and Raw SQL, both don't work

public function updateResponse($state,$sugester,$sugested,$location_id)
{
    $sql = "UPDATE Sugestion SET state=$state WHERE sugester=$sugester AND sugested=$sugested AND location_id=$location_id;";
    $sugestion = new Sugestion();
    return new Resultset(null, $sugestion, $sugestion->getReadConnection()->query($sql));
}

Thank you so much!

Try this.

public function updateResponse($state, $sugester, $sugested, $location_id) {
    $Sugestion = Sugestion::findFirst("sugester = '{$sugester}' AND sugested = '{$sugested}' AND location_id = '{$location_id}'");
    $Sugestion->state = $state;
    $Sugestion->save();
}