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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退