2013-01-14 3 views
0

ZF2는 다음과 같이 시도했지만 ZF1이 작동하는 쿼리 결과를 제공하지 않습니다. ZF2는 작동하지 않습니다. ZF2 데이터베이스 어댑터가 불완전하고 ZF2 자체에서 해결되지 않은 버그가 있습니까? 원인 문서는 그렇게하도록 지시하지만 단순히 작동하지 않습니다. ZF2 어댑터가 작동합니까?젠드 프레임 워크 2 - 어떻게 데이터베이스에 연결하고 쿼리 결과를 검색합니까?

TestController.php

<?php 
namespace Application\Controller; 
//namespace Application\Model; 
use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 
use Zend\Db\Adapter\Adapter; 
use Zend\Debug\Debug; 

class TestController extends AbstractActionController { 

    public function indexAction() { 
    $sql = "SELECT * FROM stackoverflow"; 
    $statement = $this->adapter->query($sql); 
    $res = $statement->execute(); 
    Debug::dump($res); 
    exit; 
    } 
} 

Module.php

<?php 
namespace Application; 
use Zend\Mvc\ModuleRouteListener; 
use Zend\Mvc\MvcEvent; 
use Zend\Mvc\Router\Http; 
class Module { 

    public function getServiceConfiguration() 
    { 
     return array(
      'factories' => array(
       'adapter' => function($sm) { 
        $config = $sm->get('config'); 
        $dbAdapter = new \Zend\Db\Adapter\Adapter($config['db']); 
        return $dbAdapter; 
       } 
     ), 
    ); 
    } 
} 

global.php

<?php 
return array(
// 'di' =>array(
//  'instance' =>array(
//   'PDO' => array(
//    'parameters' => array(
//     'dsn'   => 'mysql:dbname=mydb;host=localhost', 
//     'username'  => 'mydb', 
//     'password'  => '', 
//    ) 
//   ), 
//    
//   'User' => array(
//    'parameters' => array(
//     'pdo' => 'PDO' 
//    ) 
//   ) 
//  ) 
// ), 


    'db' => array(
     'driver' => 'Pdo', 
     'dsn'   => 'mysql:dbname=mydb;host=localhost', 
     'username'  => 'mydb', 
     'password'  => '', 
//  'driver_options' => array(
//   PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' 
//  ), 
    ), 


// 'service_manager' => array(
//  'factories' => array(
//   'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', 
//  ), 
// ), 
); 

답변

3

$res 결과 집합이다. ZF manual에서 결과 집합의 데이터를 추출하는 방법에 대해 자세히 읽을 수 있습니다.

+0

이, 그것은 하나의 기록을 표시하지 않습니다 {

$resultSet = $this->tableGateway->select(); return $resultSet; 

}

공공 기능 fetchAll(). – YumYumYum

1

// 방금 zf2를 시작했지만 방금 이와 같은 데이터를 검색 할 수있는 것처럼 보입니다. 덤프를하는 동안 당신은 결과를 얻을 방법을 설명하지 않습니다