how to connect to the database in zend with dsn line

427 Views Asked by At

zend framework 1.x

how to receive zend db_adapter and connect to mysql having dsn like

mysql://john:pass@localhost:3306/my_db

previously was always using this way:

$connectParams = array('dbname' => MY_DB,
        'password' => MY_PASS,
        'username' =>  MY_USER,
        'host' => MY_HOST,
        'slave' => array(),
        'maxQueryAllowedTime' => 500,
        'logQueries' => false);

return new \Db_Adapter_Pdo_Mysqlreplicator($connectParams);

sure i can parse dsn and use usual way, just curious if i can use DSN directly, coz PDO can use it but i cant find how to use it through Zend Db_Adapter

1

There are 1 best solutions below

1
On

If you are using ZendFramework 1.x ->Try this:-

$config = array('dbname' => 'yourDbName',
        'password' => 'yourpassword',
        'username' =>  'root',
        'host' => 'localhost',
        'slave' => array(),
        'maxQueryAllowedTime' => 500,
        'logQueries' => false);
$adapter = new Zend_Db_Adapter_Mysqli($config);
if ($config) {
    echo ' connected';
}