Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



33.7k
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;
    }
}
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.