Zeta Components Manual :: Docs For Class ezcDbFactory
Database::ezcDbFactory
Class ezcDbFactory
ezcDbFactory manages the list of known database drivers and is used to create their instances.
Example:
- $dbparams = array(
- 'type' => 'mysql',
- 'dbname' => 'test',
- 'user' => 'john',
- 'pass' => 'topsecret' );
- $db->query( 'SELECT * FROM tbl' );
Instead of passing an array with those parameters, you can also pass a DSN:
- $dsn = "mysql://root@localhost/geolocation";
Other examples of DSNs are:
- $dsn = "sqlite:///tmp/ezc.sqlite"; // Disk based databases for SQLite.
- $dsn = "sqlite://:memory:"; // In memory databases for SQLite.
Note that this class does not deal with character sets automatically, you have to make sure that you do that yourself. For MySQL that means running a query "SET NAMES" for example. See the tutorial for some hints on this.
Source for this file: /Database/src/factory.php
Version: | //autogentag// |
Method Summary
public static void |
addImplementation(
$implementationName
, $className
)
Adds a database implementation to the list of known implementations. |
public static ezcDbHandler |
create(
$dbParams
)
Creates and returns an instance of the specified ezcDbHandler implementation. |
public static array(string) |
getImplementations(
)
Returns a list with supported database implementations. |
public static array |
parseDSN(
$dsn
)
Returns the Data Source Name as a structure containing the various parts of the DSN. |
Methods
addImplementation
Adds a database implementation to the list of known implementations.
$implementationName is the name of the implemenation. This name should be short and uniquely identify the database. $className is the class name of the class that implements the handler for this database.
Example:
- class DB2Handler
- {
- }
- // ...
- $dbparams = array( 'handler' => 'db2', ... );
Parameters:
Name | Type | Description |
---|---|---|
$implementationName |
string | |
$className |
string |
create
Creates and returns an instance of the specified ezcDbHandler implementation.
Supported database parameters are:
- phptype|type|handler|driver: Database implementation
- user|username: Database user name
- pass|password: Database user password
- dbname|database: Database name
- host|hostspec: Name of the host database is running on
- port: TCP port
- charset: Client character set
- socket: UNIX socket path
Parameters:
Name | Type | Description |
---|---|---|
$dbParams |
mixed | Database parameters (driver, host, port, user, pass, etc). May be specified either as array (key => val ....) or as DSN string. Format of the DSN is the same as accepted by PEAR::DB::parseDSN(). |
Exceptions:
Type | Description |
---|---|
ezcDbHandlerNotFoundException |
if the requested database handler could not be found. |
getImplementations
Returns a list with supported database implementations.
Example:
parseDSN
Returns the Data Source Name as a structure containing the various parts of the DSN.
Additional keys can be added by appending a URI query string to the end of the DSN.
The format of the supplied DSN is in its fullest form:
- phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
Most variations are allowed:
- phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
- phptype://username:password@hostspec/database_name
- phptype://username:password@hostspec
- phptype://username@hostspec
- phptype://hostspec/database
- phptype://hostspec
- phptype(dbsyntax)
- phptype
This function is 'borrowed' from PEAR /DB.php .
Parameters:
Name | Type | Description |
---|---|---|
$dsn |
string | Data Source Name to be parsed |