ZF2 execute statement how to

元气小坏坏 提交于 2019-12-11 14:46:41

问题


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.

来源:https://stackoverflow.com/questions/17925428/zf2-execute-statement-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!