I am builing an app with yii and I tried doing my sql calls the "pretty way" using the yii query builder the same way seen on this guide
http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder
And this is my built query:
$diseaseCountSqlQuery = Yii::app()->db->createCommand()
->select ('tbl_disease.ICD10, COUNT(tbl_disease.ICD10) AS disease_count')
->from ('tbl_disease')
->join ('tbl_symptom_disease', 'ICD10=diseaseCode')
->where ($symptomsOrQueryArray)
->group ('ICD10')
->queryAll();
//placeholder
$maxDiseaseCountQuery = Yii::app()->db->createCommand()
->select ('MAX(disease_count) AS max_disease_count')
->from ($diseaseCountSqlQuery)
->queryAll();
//multiple symptom query
$diseaseCodes = Yii::app()->db->createCommand()
->select ('ICD10')
->from ($maxDiseaseCountQuery)
->join ($diseaseCountSqlQuery, 'max_disease_count=disease_count')
->queryAll();
The problem appears in the second command specifically the line:
->from ($diseaseCountSqlQuery)
I get an "strpos() expects parameter 1 to be string, array given " error.
I can solve my problem by just copying the entire mysql command into a string and then using create command, but I wanted to use this more "elegant" way. Can someone help me fix it and explain a bit how subqueries work with query builder? Thank you :)
foreach($diseaseCountSqlQuery as $part) { ...->from($part)}or whatever.