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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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


Go to End

3 Posts   1761 Views


Community Member, 33 Posts

11 July 2008 at 11:25pm


I'm trying to generate a custom query so I can specify the date format and possibly group a result set. here is my code:

$sqlQuery = new SQLQuery();
$sqlQuery->select = array('YEAR(StartDate) AS Date');
$sqlQuery->from = "ProjectItem";
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute();

I'm trying to select the StartDate from my 'ProjectItem' table.

The problem is the query returns an error:

FATAL ERROR: implode() [function.implode]: Invalid arguments passed

I'm pretty sure its the 'from' clause, my table exists and the fields are correct.

Anybody know where i'm going wrong.

Thanks in advance


Administrator, 690 Posts

14 July 2008 at 3:56pm

->select and ->from should be arrays

Try changing the two lines to this:

$sqlQuery->select[] = array('YEAR(StartDate) AS Date');
$sqlQuery->from[] = "ProjectItem";


Community Member, 8 Posts

6 September 2008 at 1:41am

Edited: 06/09/2008 1:42am

I am trying this query

$sqlQuery = new SQLQuery();
			$sqlQuery->select = array(
			  'ProductName AS ProductName',
			  'Industry AS Industry',
			  'Type AS Type',
			  'Serving AS Serving',
			  'Info AS Info',
			  'ReviewsBuzz AS ReviewsBuzz',
			  'Technology AS Technology',
			  'WhatsCooking AS WhatsCooking'
			$sqlQuery->from[] = "
			$sqlQuery->where[] = "
			  ID = 1";
                       // get the raw SQL
			$rawSQL = $sqlQuery->sql();
			echo $rawSQL;
			// execute and return a Query-object
			return $result = $sqlQuery->execute();

But it did not return any thing ...
i tried this as echoing echo $rawSQL;

SELECT ProductName AS ProductName, Industry AS Industry, Type AS Type, Serving AS Serving, Info AS Info, ReviewsBuzz AS ReviewsBuzz, Technology AS Technology, WhatsCooking AS WhatsCooking FROM SubProducts WHERE ( ID = 1)

this is working fine in phpmyadmin ...
Also i tried
echo "<pre>";
			echo "</pre>";

it display me
MySQLQuery Object
    [database:private] => MySQLDatabase Object
            [dbConn:private] => Resource id #89
            [active:private] => 1
            [database:private] => SS_mysite
            [mysqlVersion:private] => 
            [tableList:protected] => 
            [fieldList:protected] => 
            [indexList:protected] => 
            [schemaUpdateTransaction:protected] => 
            [extension_instances:protected] => Array

            [class] => MySQLDatabase

    [handle:private] => Resource id #132
    [currentRecord:private] => 
    [rowNum:private] => -1
    [extension_instances:protected] => Array

    [class] => MySQLQuery

i am not getting how to get result from this ...
Please help me ...
Thanks in Advance