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.

Why is this query not working

Hi,

i tried since hours to get an result from this query:

             $likes = Likes::query()
            ->where("usersId = :usersId:")
            ->andWhere("clickedId = :clickedId:")
            ->andWhere("likeClicks = :likeClicks:")
            ->bind(["usersId" => 48, "clickedId" => 0,"likeClicks" => 0  ])
            ->execute();

Debugged

 SELECT `likes`.`id`, `likes`.`usersId`, `likes`.`clickedId`, `likes`.`likeClicks` FROM `likes` WHERE ((`likes`.`usersId` = :usersId) AND (`likes`.`clickedId` = :clickedId)) AND (`likes`.`likeClicks` = :likeClicks)

In phpmyadmin i get an result, but in Phalcon it is empty, when i call $likes->usersId.

i tried several queries, also raw, same result.

Thx Stefan



86.1k
Accepted
answer
edited Apr '18

Your code returns multiple results. See for yourself print_r($likes);.

Either use $likes[0]->usersId or read more how to fetch a single result in section Model Resultsets here https://docs.phalconphp.com/zh/3.2/db-models



37.4k

Yes that is it :-)

Thx