Zend / Db在Zend Framework 3中不起作用?

时间:2017-01-12 07:05:58

标签: php pdo zend-framework3

如何使用ZF3 db factory方法连接mysql数据库。

$db = Zend_Db::factory('Pdo_Mysql', array(
      'host'      => MASTER_HOST,
      'username'  => MASTER_USER,
      'password'  => MASTER_PASSWORD,
      'dbname'    => DB_ADMIN,
      'port'      => MASTER_HOST_PORT,
      );

1 个答案:

答案 0 :(得分:0)

在ZF3(或ZF2)中,您必须使用Zend\Db\Adapter\Adapter

$config = array(
  'driver'   => 'Pdo',
  'dsn'      => 'mysql:dbname=db;host=localhost',
  'username' => 'root',
  'password' => 'root',
);
// or
$config = $serviceLocator->get('Config')['db'];

$db = new \Zend\Db\Adapter\Adapter($config);

文档:

https://framework.zend.com/manual/2.4/en/modules/zend.db.adapter.html https://framework.zend.com/manual/2.4/en/tutorials/tutorial.dbadapter.html