问题
I'm using CodeIgniter's active record features but I'm not able to select the data I'm interested in.
What I want to be selected is:
CONCAT(t.field1, ' / ', t.field2) AS `finalValue`
So I add this:
$this->db->select('CONCAT(t.field1, \' / \', t.field2) AS `finalValue`');
But this is the query string that's generated:
CONCAT(t.field1, `'` / ', `t`.`field2)` AS `finalValue`
Is this a bug? Am I specifying it incorrectly?
回答1:
You can actually turn off the default escaping mechanism, which is the source of a strange issue when using MySQL functions, by passing FALSE as the second parameter of 'select' method.
Be aware that you must then handle escaping yourself if you do this.
Oh, and you could use double quotes to reduce all that escaping you have going on.
回答2:
do this instead?
$this->db->select("CONCAT(t.field1, ' / ', t.field2) AS `finalValue`");
I.E Double quotes round the outside to avoid the need for unsightly escaping
来源:https://stackoverflow.com/questions/4519838/concat-function-in-a-select-field-list