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

PHQL update query not working

$manager = $this->modelsManager;
$query = $this->modelsManager->createQuery("update cus_detail set device_mac = '$UsrMac' where uname = '$UserName'");
$test = $query->execute();

The update query not working. Instead of updating a row, the above query inserting new row every time.

What phalcon version?



24.2k
edited May '17

Version 2.1.0r on a Windows 10 development machine with IIS 10 express.

Then i would try latest phalcon 3.1.0 maybe. Is doing pretty much the same:

$result = Cus_detail::find("uname = '$userName'");
$result->update(['device_mac' => $usrMac]);

works? This is what phalcon phql actually do - translate this query to select + oop update. Also you should uset binding in this example anyway.



24.2k
edited May '17

Clear the problem by adding unique column name id. Now it working without any problem.

edited May '17

Yea phalcon requires unique column pretty much. Keep in mind if you were aiming for performance with this - then it pretty much works as i provided above, it select first - then loop through each object and call update method.