phpmysqlnotorm

update a single record in NOTORM


I am trying to update a single record using the NOTORM library. I have a userID and need update the password column. I cannot find any code examples for just updating one record. here is the code have now which does not work it updates every record instead of the just one with the right userID.

$dbdata = array(
"Password" => $password
);
$result =  $db->$databasetable->where("id = ?", $userdata['UserID'])->update($dbdata);

echo $result;

Solution

  • Try this:

    $dbdata = array(
            "Password" => $password
        );
    
    $user = $db->$databasetable->where("id = ?", $userdata['UserID'])-fetch()
    
    if ($user !== false) {
        $result = $user->update($dbdata);
        echo $result;
    } else {
        //TODO;
    }
    

    $result is affected row