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.

Problem with PHQL

I have the following Phql query:

$arrRs = $this->modelsManager->executeQuery("SELECT * FROM Phrase p inner join  User u  on p.user = u.id  where (p.phrase like '% :search: %' or   u.codeLink2me = ':search:')", array('search' => $searchInput));

When I run it, it gives me an $arrRs->valid() as a false. But when i ran SQL version of the Phql query, its return the expected results

$sql = "SELECT * FROM phrases p inner join users u on p.phrase_id = u.user_id WHERE (p.str_phrase like '%$searchInput%' or u.str_cod_link = '$searchInput')";
$user = new User();
$links = new Phalcon\Mvc\Model\Resultset\Simple(null, $user, $user->getReadConnection()->query($sql, ''));

Am I missing something?



84.5k
Accepted
answer

You can't enclose a placeholder in simple/double quotes because it will handle the placeholder as a string, you have to do:

$arrRs = $this->modelsManager->executeQuery("SELECT * FROM Phrase p inner join User u on p.user = u.id where (p.phrase like :search: or u.codeLink2me = :search:)", array('search' => '%' . $searchInput . '%'));


2.6k

Thank you very much.