【问题标题】:zf2 - join using a using Zend\Db\TableGateway\TableGateway;zf2 - 使用 Zend\Db\TableGateway\TableGateway 加入;
【发布时间】:2013-02-04 00:21:41
【问题描述】:

我想使用 zf2 从第一个表和第二个表中选择字段进行简单连接,但是当我尝试将字段数组放入 columns 方法时出现错误(“无法执行语句”)。

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);
    });  
...
}

【问题讨论】:

标签: zend-framework2 tablegateway


【解决方案1】:

您需要确保 dateTime/id 字段位于您提供的列列表中。

如果您转储异常 ($e->getTraceAsString()),您将获得有关导致错误的原因的更多信息。

【讨论】:

    【解决方案2】:

    评论此语句在数组中添加至少一个有效的“列”名称(表列/字段名称)。

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

    空白的$select->columns(); 语句会生成类似于SELECT FROM table_name 的sql 查询,这会导致错误。

    当你评论这条语句时,它会生成像SELECT * FROM table_name这样的sql查询 如果你传递列名,星号被它们替换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2014-06-08
      相关资源
      最近更新 更多