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

NOTIFICATION ON THE API NOT WORKING

I made the edit password based on uid and account is value 1, then i check the results show "Updated" and the data in the database i check also successfully updated, but when i check in the column of account is value 0, the data in the database was not successfully updated, but the notification shows "Updated",it's should be "ERROR"

$phql = "UPDATE Users SET password=:password: WHERE uid=:uid: AND account=:account:";

    $status = $app->modelsManager->executeQuery(
        $phql,
        [
            'uid'           => $uid,
            'password'  => md5($_POST['password']),
            'account' => '1'
        ]
    );

$response = new Response();

   if (count($status) > 0) {

            $response->setJsonContent(
                array(
                    'status' => 'Updated'
                )
            );
   } else {

        $response->setJsonContent(
                array(
                    'status' => 'ERROR'
                )
            );
    }
return $response;

}



8.2k
Accepted
answer
edited Sep '17

First off, don't use MD5 to hash passwords. use password_hash()

Second, SQL always returns a status containing the amout of row effected by a command. so your count will always equal 1.

you should be using $status->rows_effected > 0 I think

edited Sep '17

if use password_hash(), it's result not change of password in the database and for $status->rows_effected > 0 it result is error

edited Sep '17

if use password_hash(), it's result not change of password in the database and for $status->rows_effected > 0 it result is error

Then you should maybe try execute the command manually. see if you get errors. If not, dump what you get back from the database in phalcon.

OK, Thank you very much for helping me..