Jump to content
Larry Ullman's Book Forums

Yii Query Builder Quick Question


Jonathon
 Share

Recommended Posts

I was reading the docs for the select call http://www.yiiframework.com/doc/api/1.1/CDbCommand#select()-detail

 

it says:

 

Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name'))

 

I've actually done some hybrid version with

 

 

$cmd->select(array('column1, column2, column3'));

 

Will that be problematic at all?

 

I can change it, it looked ok in my log. But I wanted to be sure.

 

Jonathon

Link to comment
Share on other sites

I don't know offhand if that'd be a problem. You can test it to confirm. But my inclination would be to either send a string or an array of strings. There's really no reason to do it this way (now that you've caught it).

Link to comment
Share on other sites

It works because the query builder alters your input to work in several different forms. As long as the input is either:

 

a.) A String that is a DB expression, i.e has parenthesis. COUNT(something)... or

b.) Is a String (that will be exploded to an array first thing), or an array with elements that validates a regular expression...

 

...It will work. All valid elements found in your array will be kept, and the invalid ones removed. If it's an array, all valid elements will be exploded into a single String in the end. The "magic" here is obviously the regular expression, that is smart enough to judge your single array element of several DB columns as valid input.

 

https://github.com/yiisoft/yii/blob/1.1.13/framework/db/CDbCommand.php#L603

Link to comment
Share on other sites

 Share

×
×
  • Create New...