如何使用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,
);
答案 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