yii - Construct CDbCriteria with column names as MySQL reserved words -
i have same problem in this question (attempt utilize cdbcriteria
column named key
, reserved word in mysql). however, provided solution:
$criteria = new cdbcriteria; $criteria->condition = 't.key=:key'; $criteria->params = array(':key'=>$this->key); $criteria->compare('position', $this->position); $criteria->compare('dictionary', $this->dictionary);
works me partially. don't exception anymore, search works key
column only. other ignored (if key
set, respects value in search, if not set -- returns empty results set).
what missing? how should build cdbcriteria
queries, when table contains reserverd words column names, search respect other (non-reserved) columns well, not one?
cdbcriteria::compare()
adds status if parameter set otherwise no action taken.see here
$criteria->condition = 't.key=:key'; $criteria->params = array(':key'=>$this->key);
however logic works irrespective of whether key set or not. status becomes
select * `some_table` t t.key =:key
even though key value beingness blank resulting in query breaking when key attribute not set
so if modify statement work
if(isset($this->key){ $criteria->condition = 't.key=:key'; $criteria->params = array(':key'=>$this->key); }
in case statement activated when key attribute set, ignored otherwise, , query not break
yii
No comments:
Post a Comment