0

I want to do a simple join using zf2 selecting fields from the first and second table, but I get an error ('Statement could not be executed') when I try to put an array of fields into the columns method.

public function fetchAll()
{
    $resultSet = $this->tableGateway->select(function (Select $select) {
        $select->columns();// ->with params gives an 'Statement could not be executed'
        $select->join(array('t2' => 'categories'), 'table1.idCategory = t2.id');
        $select->order('dateTime DESC')->limit(100);
    });  
...
}
GingerHead
  • 8,130
  • 15
  • 59
  • 93
jj-aa
  • 1,019
  • 5
  • 19
  • 39
  • You can find the answer here -> http://stackoverflow.com/questions/14354802/tablegateway-with-multiple-from-tables/14371056#14371056 – Diemuzi Feb 04 '13 at 15:21
  • Can you show an example you are using when it return the exception? – Andrew Feb 08 '13 at 09:26

2 Answers2

0

You will need to make sure the dateTime/id fields are in the column list you provide.

If you dump out the exception ($e->getTraceAsString()) you will get some more information about what is causing your error.

Andrew
  • 12,617
  • 1
  • 34
  • 48
0

Either comment this statement Or add atleast one valid 'column' name in array (table column/field name).

$select->columns(array('column_one', 'column_two', 'column_N'));

A blank $select->columns(); statement generates sql query something like SELECT FROM table_name which results in error.

When you comment this statement, it generates sql query like SELECT * FROM table_name and if you pass column names, asterisk replaced by them.

webcoder
  • 1,355
  • 1
  • 15
  • 14