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;

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();

use Zend\Db\Sql\Sql;
use Zend\Db\Adapter\Adapter;

$dbAdapterConfig = array(
    'driver'   => 'Mysqli',
    'database' => 'dbname',
    'username' => 'dbusername',
    'password' => 'dbuserpassword'
);
$dbAdapter = new Adapter($dbAdapterConfig);

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

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

Doc:http://framework.zend.com/manual/2.1/en/index.html#zend-db / http://framework.zend.com/manual/2.1/en/modules/zend.db.sql.html