I have a simple table set up like this:
1. hello 100 30
2. hellp 100 32
3. help 25 32
I can retrieve the first two lines just fine using DataObject::get with this code:
$crit = "'hell%'";
$obj = "testtable";
$filter = "textfield1 LIKE ".$crit;
$sort = "";
$join = "";
$limit = "";
$data1 = DataObject::get($obj, $filter, $sort, $join, $limit);
Debug::dump($data1);
BUT the problem with dataobject::get is that lacks the ability to select specific columns, COUNT or DISTINCT and I want to use the DISTINCT statement for the rest of my code
So I'm trying to use SQLQuery:
$crit = "'hell%'";
$sqlQuery = new SQLQuery();
$sqlQuery->select = array( '*',);
$sqlQuery->from = array("testtable",);
$sqlQuery->where = array("textfield1 LIKE ".$crit,);
$rawSQL = $sqlQuery->sql();
Debug::dump($rawSQL);
$data = $sqlQuery->execute();
Debug::dump($data);
But for some reason the above code always results in nothing but a blank dataobjectset!
According to $rawSQL it tries to run this:
SELECT * FROM testtable WHERE (textfield1 LIKE 'hell%')
Which works just fine if I enter it in phpmyadmin! So why can't silverstripe produce any results? Can someone please point out what is wrong with my code?