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

Struggling with Update

I am trying to run an UPDATE query on my media table, but i don't know why it is not working! My SELECT statement is wokring fine but UPDATE is not! I am using Phalcon Version 1.3.4

Here is my UPDATE statement:

$query = "UPDATE media SET media.mid = 2 WHERE media.name LIKE test";
$this->getModelsManager()->executeQuery($query);

Here is my SELECT statement which works fine:

$query = "SELECT media.mid FROM media WHERE media.name LIKE test";
$result = $this->getModelsManager()->executeQuery($query);

Can someone help me please?



34.6k
Accepted
answer
edited May '15

Try to see what messages are being returning!

$query = "UPDATE media SET media.mid = 2 WHERE media.name LIKE test";
$status = $this->getModelsManager()->executeQuery($query);
if (!$status->success()) {
    foreach ($status->getMessages() as $message) {
        echo $message;
    }
}


1.9k
edited May '15

Thank you @Andres Gutierrez for comment:

On if($status->success()) i am getting nothing

if ($status->success()) {
    foreach ($status->getMessages() as $message) {
        echo $message;
    }
}

But, but if(!$status->success()), i am receiving a message:

mediahash is required title_clean is required

which it says i have to set two addtional parametes for colunms (mediahash & title_clean) while running Update Query. I set these parameters and it works fine.