I would like to know how can I execute a query, inside a phalcon controller, using parameters.
My SQL Query:
SELECT a.*, getApplicationData(a.id) as json_data
FROM application a
INNER JOIN application_data d on d.application_id = a.id
AND d.firstname LIKE '%:searchQuery:%' ;
$applications = $this->db->query(
You almost got it right. You only had to add the percents (%) in the bind array.
$sqlQuery = 'SELECT * FROM events WHERE title LIKE :searchQuery'; $applications = $this->db->query( $sqlQuery, array('searchQuery'=> '%' . $searchQuery . '%') )->fetchAll();
Also notice how I binded the :searchQuery in the
$sqlQuery. It only uses single : instead of surrounding the parameter. This is because Raw queries use directly the DB connection in our case it is PDO.
More examples can be found here: https://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo.html