Fork me on GitHub

ADODB to DBUtils  Bottom

  • Here is a select statement that works fine in the ADODB world but now I need to move to DBUtils... how can I do this:

    Code

    $pntable =& pnDBGetTables();

        $MyDogsOutsideTable = $pntable['mydogs_outside'];
        $MyDogsOutsideColumn = &$pntable['mydogs_outside_column'];

        $where = "";
        $stateList = "";
        $cnt = 0;
        if (strlen($args['states'])) {
          $slist = explode(',', $args['states']);
          foreach ($slist as $state) {
            if ($cnt++) $stateList .= ", ";
            $stateList .= "'$state'";
          }
          $where = " WHERE $MyDogsOutsideColumn[state] IN ( $stateList )";
        }

        $sql = "SELECT MIN($MyDogsOutsideColumn[tdate]) as sdate,
                       MAX($MyDogsOutsideColumn[tdate]) as edate,
                       $MyDogsOutsideColumn[vname],
                       $MyDogsOutsideColumn[club],
                       $MyDogsOutsideColumn[location]
                FROM $MyDogsOutsideTable
                $where
                GROUP BY $MyDogsOutsideColumn[club],
                         $MyDogsOutsideColumn[odate]
                ORDER BY sdate,
                         $MyDogsOutsideColumn[state]"
    ;

        $result =& $dbconn->Execute($sql);



    I tried the following but it didn't work... Exit-Handler: Invalid objectColumns received

    Code

    $selArray = array('sdate' ,
                         'edate' ,
                         'vname' ,
                         'club' ,
                         'location' );
        $items = DBUtil::selectObjectSQL($sql, $MyDogsOutsideTable, $selArray);


    So I am trying to use the MIN and MAX operation on the Select statement but it looks like I don't get a proper column matching. So is there a way to do this?

    Thanks!
  • Hi,

    you can't do this using DBUtil directly. The best thing to do is to do the following:

    Code

    $result = DBUtil::executeSQL ($sql);
    $items = DBUtil::marshallObjects ($results, $columnArray);


    Greetings
    R

This list is based on users active over the last 60 minutes.