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.

Data Model Questions /

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

SQLSelect Question


Go to End


1370 Views

Avatar
mi32dogs

Community Member, 75 Posts

20 April 2016 at 5:18pm

How do I get a 0 count on SQLSelect call

If I do a SQLSelect call let’s say:

$sqlQuery = SQLSelect::create()
->setFrom("Soup_Live")
->selectField('ID', 'ID')
->addWhere("Soup = ‘Tomato'");

$Soups = $sqlQuery->execute();

If(count($Soups)>1){
Echo “I like soup”
}

Now this works fine if there are records returned but if there are no records the count comes still back with 1 as the object returned is not empty it returns
“MySQLQuery::__set_state(array( 'handle' => mysqli_result::__set_state(array( 'current_field' => NULL, 'field_count' => NULL, 'lengths' => NULL, 'num_rows' => NULL, 'type' => NULL, )), 'currentRecord' => NULL, 'rowNum' => -1, 'queryHasBegun' => false, ))”

Is there any way to get a 0 count?