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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1317 Views

Avatar
tim32

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 belminuten.net.
I have created a custom page that does a query for data. Please find the code below.

$sqlQuery = new SQLQuery();
$sqlQuery->setFrom('simonly_abo');
$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.'\'');
$sqlQuery->setOrderBy('abo_price');
$sqlQuery->selectField('img','img');

$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?

Regards,
Jombo.

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

Avatar
dhensby

Community Member, 253 Posts

4 August 2013 at 2:33am

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