dtv995719 2014-07-17 08:23
浏览 79
已采纳

zend框架中的mysql查询2

$dbAdapter = $this->adapter;
        $sql = new Sql($dbAdapter);
        $sQuery = $sql->select()
                ->from(array('c' => 'company'), array('name', 'jobtitle', 'experience', 'skill'))
                ->joinInner(array('j' => 'jobpost'), 'c.cid = j.cid');

In this query, I am getting error:

PHP Fatal error: Call to undefined method Zend\Db\Sql\Select::joinInner().

And classes i used in this :

use Zend\Db\Adapter\Adapter;

use Zend\Db\Sql\Sql;

use Zend\Db\TableGateway\AbstractTableGateway;

  • 写回答

2条回答 默认 最新

  • dongliang1873 2014-07-17 09:09
    关注

    You should remove joinInner and add join

    $dbAdapter = $this->adapter;
            $sql = new Sql($dbAdapter);
            $sQuery = $sql->select()
                    ->from(array('c' => 'company'), array('name', 'jobtitle', 'experience', 'skill'))
                    ->join(array('j' => 'jobpost'), 'c.cid = j.cid');
    

    By default it will do an Inner join. If you want to specify the join then the documentation example from zend

    should make it clear.

    $select->join(
         'foo' // table name,
         'id = bar.id', // expression to join on (will be quoted by platform object before insertion),
         array('bar', 'baz'), // (optional) list of columns, same requiremetns as columns() above
         $select::JOIN_OUTER // (optional), one of inner, outer, left, right also represtned by constants in the API
    );
    

    You will also need the two lines Hary added in his answer,

    $statement = $sql->prepareStatementForSqlObject($sQuery);
    $result = $statement->execute();
    

    and the you can return your result

    return $result->toArray();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图