Database PDO DataSourceName Demo

This is a demonstration of the features of the cmClasses class Database_PDO_DataSourceName.

1. Using Object Instance

$dba = parse_ini_file( 'dba.ini.inc' ); $dsn = new Database_PDO_DataSourceName( $dba['driver'] ); $dsn->setDatabase( $dba['database'] ); $dsn->setHost( $dba['host'] ); $dsn->setPort( $dba['port'] ); $dsn->setUsername( $dba['username'] ); $dsn->setPassword( $dba['password'] ); Will create an object which can be given to Database_PDO_Connection or can be casted to a DSN string. mysql:host=localhost;dbname=test Rendered in 0.5 ms.

2. Using Static Call

You can create a DSN string using a static call like this: $dsn = Database_PDO_DataSourceName::renderStatic( $driver, $dbname, $host, $port, $user, $pass ); which, again, will create an Object for Database_PDO_Connection and is renderable to string.

3. Supported PDO Drivers

firebird
firebird:DataSource=localhost;Database=test;User=user1;Password=pass1
mssql
mssql:host=localhost;dbname=test
mysql
mysql:host=localhost;dbname=test
oci
oci:dbname=//localhost/test
pgsql
pgsql:host=localhost dbname=test user=user1 password=pass1
sqlite
sqlite:test
sybase
sybase:host=localhost;dbname=test
Rendered in 0.4 ms.