ZF2执行语句如何

时间:2013-07-29 13:30:23

标签: php mysql zend-framework2

我想知道我做错了什么。 这是我的班级。

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

运行函数getCity()

上的VAR_DUMP
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
}

我在谷歌搜索之前在这里发帖并尝试了很多东西但结果相同。我无法从数据库中检索任何数据。

0 个答案:

没有答案