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.

Archive /

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

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

SQLQuery()


Reply


3 Posts   1450 Views

Avatar
thejackel

Community Member, 33 Posts

11 July 2008 at 11:25pm

Hi,

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

Avatar
Sam

Administrator, 685 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";

Avatar
Rahul

Community Member, 8 Posts

6 September 2008 at 1:41am

Edited: 06/09/2008 1:42am

Hi,
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[] = "
          SubProducts         
         ";
         $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>";
         print_r($result);
         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