ZF2 execute statement how to

2019-08-02 05:42发布

I'd like to know what I'm doing wrong. This is my class.

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

class Country
{
    protected $_dbA;
    protected $_sql;

    public function __construct(Adapter $dbA) {
        $this->_dbA = $dbA;
        $this->_sql = new Sql($this->_dbA);
    }

    public function getCity()
    {
        $select = new Select();
        $sql = $select->from('es')
                      ->columns(array('City'))
                      ->where(array('ZIP' => 28934));
        if (is_string($sql)) {
            $stm = $this->_dbA->createStatement($sql);
        } else {
            $stm = $this->_dbA->createStatement();
            $sql->prepareStatement($this->_dbA, $stm);
        }
        return $stm->execute();
    }
}

And VAR_DUMP on running function getCity()

object(Zend\Db\Adapter\Driver\Pdo\Result)#332 (8) {
  ["statementMode":protected]=>
  string(7) "forward"
  ["resource":protected]=>
  object(PDOStatement)#331 (1) {
    ["queryString"]=>
    string(60) "SELECT `es`.`City` AS `City` FROM `es` WHERE `ZIP` = :where1"
  }
  ["options":protected]=>
  NULL
  ["currentComplete":protected]=>
  bool(false)
  ["currentData":protected]=>
  NULL
  ["position":protected]=>
  int(-1)
  ["generatedValue":protected]=>
  string(1) "0"
  ["rowCount":protected]=>
  NULL
}

I searched in Google before posting here and tried many things but with same result. I can't retrieve any data from Data Base.

0条回答
登录 后发表回答