1

如何使用 ZF3 数据库工厂方法连接 mysql 数据库。

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

1 回答 1

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

于 2017-01-13T07:36:05.127 回答