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

phalcon update query not working for non primary key

phalacon framework ->update not working for non primary keys

edited Sep '15

Records map to a single object in PHP, update the primary key means the object transmutate into another instance which is a bad idea.



1.1k

CREATE TABLE IF NOT EXISTS scormvars ( SCOInstanceID int(10) unsigned NOT NULL DEFAULT '0', varName varchar(255) DEFAULT NULL, varValue text, KEY SCOInstanceID (SCOInstanceID), KEY varName (varName) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO scormvars (SCOInstanceID, varName, varValue) VALUES (220, 'cmi.core.lesson_status', 'incomplete'), (220, 'cmi.core.session_time', '00:07:33'), (220, 'cmi.suspend_data', 'ver=1.0.22|node_data=[{UwETVBSctUGpTELJFXAzew}#status=CC][{s0AYDBlKBEu5gj4IOdvuiw}#status=N][{8flqvL-kGUeEOOxjgL8WnQ}#status=NNNN][{-nojFJmcDk-UvfP3APYRDg}#status=NNNNNNNNN][{AjSPzPzQfUCxBPEkaBLGuQ}#status=N][{u2OWdHHCLkKpNTK4oEW5tg}#status=NNNNNNN][{TQfKG0-DnU2caw7WiwhLpw}#status=N][{YdMgGtQtPUaFtpqLYQFGUA}#status=N][{qQbRd2nF20-T-4plCROCbg}#status=NNNN][{X6KGIeVaDEiWcpXZxISwsA}#status=NNNNNN][{QHP7DlMy-02lR3FMEbPsrQ}#status=NN][{r7nOuticIkaJHcGfsJWNgw}#status=NNN][{54VZsqsK6E-Ri-9J6yJIsw}#status=N][{wXdvODeahU2wHToB3WIl5g}#status=N][{3qBt11YWJUKDmNX4Vu96sA}#status=N][{hdDGjJkj-UyrQf-EaJILAg}#status=N][{rUoBd-jiIUivswVV532u0g}#status=NNNNNN][{-X08RIYBRUCV-IqwfLkUDQ}#status=NN][{vka-trRdA0WnH-rnbCAI5g}#status=NN][{wtkaEWe2DE6-HAve-5mrCA}#status=NN][{LXM0vOHYyUm1hadnzauTbw}#status=N][{vcJYErSeoEOwludDUDs-gw}#status=N][{KaT-uXcPsU28XlURdETQJg}#status=NNNNNNNNN][{kCNZIztADE6g8Oq-EJRLSA}#status=NNNNN][{ppqqJv2EhEmA5-rSzBlKhg}#status=NNNNNNNN][{36YwFmpiNUq5KD5uEsDm-w}#status=NN][{qsKJ-5OrDkuNY3WCbaaLqA}#status=NNNNNNNN][{y2fYvfMWXEyDJsfc9F-EnQ}#status=N][{8b3grpS5q0qiLHS5aHQQSQ}#status=N][{30EAdQfKcXWXyaZPPpVwfQ}#status=N][{ALZoADP-A0GVPodeAE27pA}#status=NN][{ZLZoADP-r0GVPodeYE27pg}#status=NNNNNNNNNNN][{Z989ADP-r0GVPodeYE27pg}#status=NNN]'), (220, 'cmi.core.lesson_status', 'incomplete'), (220, 'cmi.core.session_time', '00:07:33'), (220, 'cmi.suspend_data', 'ver=1.0.22|node_data=[{UwETVBSctUGpTELJFXAzew}#status=CC][{s0AYDBlKBEu5gj4IOdvuiw}#status=N][{8flqvL-kGUeEOOxjgL8WnQ}#status=NNNN][{-nojFJmcDk-UvfP3APYRDg}#status=NNNNNNNNN][{AjSPzPzQfUCxBPEkaBLGuQ}#status=N][{u2OWdHHCLkKpNTK4oEW5tg}#status=NNNNNNN][{TQfKG0-DnU2caw7WiwhLpw}#status=N][{YdMgGtQtPUaFtpqLYQFGUA}#status=N][{qQbRd2nF20-T-4plCROCbg}#status=NNNN][{X6KGIeVaDEiWcpXZxISwsA}#status=NNNNNN][{QHP7DlMy-02lR3FMEbPsrQ}#status=NN][{r7nOuticIkaJHcGfsJWNgw}#status=NNN][{54VZsqsK6E-Ri-9J6yJIsw}#status=N][{wXdvODeahU2wHToB3WIl5g}#status=N][{3qBt11YWJUKDmNX4Vu96sA}#status=N][{hdDGjJkj-UyrQf-EaJILAg}#status=N][{rUoBd-jiIUivswVV532u0g}#status=NNNNNN][{-X08RIYBRUCV-IqwfLkUDQ}#status=NN][{vka-trRdA0WnH-rnbCAI5g}#status=NN][{wtkaEWe2DE6-HAve-5mrCA}#status=NN][{LXM0vOHYyUm1hadnzauTbw}#status=N][{vcJYErSeoEOwludDUDs-gw}#status=N][{KaT-uXcPsU28XlURdETQJg}#status=NNNNNNNNN][{kCNZIztADE6g8Oq-EJRLSA}#status=NNNNN][{ppqqJv2EhEmA5-rSzBlKhg}#status=NNNNNNNN][{36YwFmpiNUq5KD5uEsDm-w}#status=NN][{qsKJ-5OrDkuNY3WCbaaLqA}#status=NNNNNNNN][{y2fYvfMWXEyDJsfc9F-EnQ}#status=N][{8b3grpS5q0qiLHS5aHQQSQ}#status=N][{30EAdQfKcXWXyaZPPpVwfQ}#status=N][{ALZoADP-A0GVPodeAE27pA}#status=NN][{ZLZoADP-r0GVPodeYE27pg}#status=NNNNNNNNNNN][{Z989ADP-r0GVPodeYE27pg}#status=NNN]')

when i try to update

UPDATE scormvars SET varValue='Finished' WHERE SCOInstanceID=220 and varName='cmi.core.lesson_status'

this will insert new raw with new insert entry instead of update

code is like that

$phql = "UPDATE Modules\Models\Entities\Scormvars SET varValue = '" . $varValue . "' WHERE SCOInstanceID = $SCOInstanceID and varName = '" . $varName . "' "; //return $Scormvars->modelsManager->executeQuery($phql);

not working