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

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



93.7k
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.phalcon.io/zh/3.2/db-models



59.9k

Yes that is it :-)

Thx