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?



13.7k
edited 17d ago

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.



13.7k
edited 16d ago

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

edited 16d ago

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.