hi,
Q1. how can I use sql query as show below? is there any configure needed in cakephp or query ? please give some guideline.
$aql = $this->Models->query("select abc from TSpec where SC= ? ,‘169/02’ ");
I feel there is limitation using find / field as below, so decide to use sql query, anybody can give some guideline,
how to use it ?
below sample was work as normal, but the above doest;t show any data ?
$aql = $this->Models->field(‘abc’, array(‘sc’ => ‘169/02’ ));
If I try to reproduce the basic query as in the documentation: $result=$this->Gpxfiles->query("SELECT 'name' FROM 'gpxfiles' LIMIT 2");
I do not receive an array, but the query object itself. Moreover, it does not contain the query I requested, but a general select * FROM :
object(Cake\ORM\Query) {
'(help)' => 'This is a Query object, to get the results execute or iterate it.',
'sql' => 'SELECT Gpxfiles.id AS Gpxfiles__id, Gpxfiles.linestring AS Gpxfiles__linestring, ... FROM gpxfiles Gpxfiles',
'params' => [],
'defaultTypes' =>...
No idea why the SQL wouldn’t match what you’re looking for. You don’t get an array, because you haven’t asked it for one, you’re presumably just outputting the actual query object.
Why not use $this->Gpxfiles->find()->select('name')->limit(2)? I’ve built some very complex systems, and have not once had to resort to using the query function.
Because eventually I want to use $result_gpx=$this->Gpxfiles->query("SELECT ST_AsGeoJSON(linestring) FROM gpxfiles WHERE id=gpx_id_string");
for which I will need a custom query. The reason why I started off with a basic question is to understand it step by step in order to understand the eventual query.
Unless you’re running this in a loop that executes thousands of times, the performance difference between the two will not be noticeable. Go with the one version that is more long-term maintainable for you.