Driver Documentation
Any PHP extension that is linked against the PDO core module can elect to
register a PDO driver. A PDO driver is represented by the
pdo_driver_t type which describes the version of PDO against
which the driver was built, the name of the driver and a factory method
that can be used to instantiate a database connection handle. A
connection handle is represented by the pdo_dbh_t type which
describes, among other things, how to instantiate a prepared statement
handle, represented by the pdo_stmt_t type.
These three types are the main interface between the PDO core and a PDO
driver. In this chapter, we'll refer to an imaginary skeleton driver, and
use SKEL as a placeholder for its various functions or
types. In practice, a given database vendor will typically choose to use
a short, lowercase, version of the name of their database or client
library in place of SKEL.
Driver Registration
A driver extension will typically statically define an instance of
pdo_driver_t and pass the address of it to
php_pdo_register_driver during its module
initialization callback (also known as MINIT, for module init), and
again to php_pdo_unregister_driver during its
module shutdown callback (also known as MSHUTDOWN).
php_pdo_driver.h defines pdo_driver_t,
php_pdo_register_driver and
php_pdo_unregister_driver as follows:
is_persistent and pass that flag to
* pemalloc() for all allocations that are stored in the dbh or your instance
* data in the db, otherwise you will crash PHP when persistent connections
* are used.
*/
int (*db_handle_factory)(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC);
} pdo_driver_t;
/* call this in MINIT to register your PDO driver */
PDO_API int php_pdo_register_driver(pdo_driver_t *driver);
/* call this in MSHUTDOWN to unregister your PDO driver */
PDO_API void php_pdo_unregister_driver(pdo_driver_t *driver);
]]>
A driver would typically use code like the following to register a
driver:
The SKEL_db_handle_factory is provided by the
driver; its operation will be discussed in the next section.