I am using cakePHP 1.26.
I was trying to update a Table using these lines of code:
$c = "helloworld";
$q="UPDATE user SET avatar='{$c}' WHERE user_id='999999'";
$result=$this->Test->User->query($q);
if($result==true){echo "success";}
else{echo "failed";}
I noticed that the Table was updated successfully, but I still saw the “failed” message.
It seems that the value of $result is neither True nor False.
I have no idea.
query()returns the result set from the SQL query. You won’t get a success vs. failure result. That said, you probably shouldn’t be usingquery()anyway. There’s a function for this; it’s calledsaveField()and it returns false on failure.If you insist on using
query()there’s no reason to go to another model. It just executes an SQL query. This would work as well as what you wrote:Incidentally,
if ($result == true)is redundant and generally considered poor form. justif ($result)will work identically.