Comments: query

By Maine on 29/10/08

1 - Query with SQL prepared statements

Query can be used to make database queries with prepared statements. It requires passing another argument 'parameters' to the query-function.

See (https://trac.cakephp.org/changeset/6687):

$query = "SELECT title, published FROM articles WHERE articles.id = ? AND articles.published = ?";

$params = array(1, 'Y');

$result = $this->Article->query($query, $params);

By vipm 3 weeks, 1 day ago

2 - Query with calculated fields

to access query results, for example:

$userinfo = $this->User->query("SELECT gender, ROUND((to_days(now()) - to_days(bday)) / 365) as age FROM users WHERE id = $userid");

This is the syntax to access the results:

$gender = $userinfo[0]['users']['gender'];

$age = $userinfo[0][0]['age'];