Preparation and Housekeeping
Source directory layout
The source directory for a typical PDO driver is laid out as follows, where SKEL represents a shortened form of the name of the database that the driver is going to connect to. Even though SKEL is presented here in uppercase (for clarity), the convention is to use lowercase characters.
pdo_SKEL/ config.m4 # unix build script config.w32 # win32 build script CREDITS package.xml # meta information about the package pdo_SKEL.c # standard PHP extension glue php_pdo_SKEL.h php_pdo_SKEL_int.h # driver private header SKEL_dbh.c # contains the implementation of the PDO driver interface SKEL_stmt.c # contains the implementation of the PDO statement interface tests/
The contents of these files are defined later in this document.
Creating a skeleton
The easiest way to get started is to use the ext_skel shell script found in the PHP build tree in the ext directory. This will build a skeleton directory containing a lot of the files listed above. It can be build by executing the following command from within the ext directory:
This will generate a directory called pdo_SKEL containing the skeleton files that you can then modify. This directory should then be moved out of the php extension directory. PDO is a PECL extension and should not be included in the standard extension directory. As long as you have PHP and PDO installed, you should be able to build from any directory.
Build Specific Headers
The header file config.h is generated by the configure process for the platform for the which the driver is being built. If this header is present, the HAVE_CONFIG_H compiler variable is set. This variable should be tested for and if set, the file config.h should be included in the compilation unit.
The following standard public php headers should be included in each source module:
PDO Interface Headers
The following standard public PDO header files are also included in each source module:
Driver Specific Headers
The typical PDO driver has two header files that are specific to the database implementation. This does not preclude the use of more depending on the implementation. The following two headers are, by convention, standard:
Depending on the implementation details for a particular driver it may be necessary to include the following header: