Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

sql query select fields

Go to End

2 Posts   989 Views


Community Member, 2 Posts

3 August 2013 at 10:45pm

Edited: 04/08/2013 1:20am

Hi all,

I am working on my website called
I have created a custom page that does a query for data. Please find the code below.

$sqlQuery = new SQLQuery();
$sqlQuery->selectField('id', 'id');
$sqlQuery->selectField('abo_type', 'abo_type');
$sqlQuery->selectField('abo_minutes', 'abo_minutes');
$sqlQuery->selectField('abo_sms', 'abo_sms');
$sqlQuery->selectField('abo_data', 'abo_data');
$sqlQuery->selectField('abo_time', 'abo_time');
$sqlQuery->selectField('abo_price', 'abo_price');
$sqlQuery->addWhere('provider = \''.$this->brand.'\'');

$result = $sqlQuery->execute();

It works great, but when i check the full query with
echo $sqlQuery->sql();

I get:
SELECT *, id, abo_type, abo_minutes, abo_sms, abo_data, abo_time, abo_price, img, CONCAT(abo_time,'_',abo_minutes,'_',abo_data) AS "slug" FROM simonly_abo WHERE (provider = 'aess44') GROUP BY slug ORDER BY abo_price ASC

I only need the fields I selected, but silverstripe puts * at the beginning of the query. How can I prevent this from happening?


UPDATE: i figured it out. I used setSelect() instead of selectField(). that solved the problem.


Community Member, 253 Posts

4 August 2013 at 2:33am

It's because the default value when you construct the object is *