How to connect mysql database using ZF3 db factory method.
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => MASTER_HOST,
'username' => MASTER_USER,
'password' => MASTER_PASSWORD,
'dbname' => DB_ADMIN,
'port' => MASTER_HOST_PORT,
);
In ZF3 (or ZF2), you must use 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);
Documentation:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.