PHP: Preparation and Housekeeping - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Fleshing out your skeleton Prerequisites

Last updated: Fri, 26 Jan 2007

view this page in

# 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
      config.w32
      CREDITS
      package.xml
      pdo_SKEL.c
      php_pdo_SKEL.h
      php_pdo_SKEL_int.h
      SKEL_dbh.c
      SKEL_stmt.c

  unix build script
  win32 build script
  meta information about the package
  standard PHP extension glue
  driver private header
  contains the implementation of the PDO driver interface
  contains the implementation of the PDO statement interface

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:

    ./ext_skel --extname=pdo_SKEL

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.

## Standard Includes

### 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.

### PHP Headers

The following standard public php headers should be included in each source module:

1. php.h

2. php_ini.h

3. ext/standard/info.h

### PDO Interface Headers

The following standard public PDO header files are also included in each source module:

pdo/php_pdo.h

  This header file contains definitions of the initialization and shutdown functions in the main driver as well as definitions of global PDO variables.

pdo/php_pdo_driver.h

  This header contains the types and API contracts that are used to write a PDO driver. It also contains method signature for calling back into the PDO layer and registering/unregistering your driver with PDO. Most importantly, this header file contains the type definitions for PDO database handles and statements. The two main structures a driver has to deal with, pdo_dbh_t and pdo_stmt_t, are described in more detail in Appendix A and B.

### 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:

php_pdo_SKEL.h

  This header file is virtually an exact duplicate in functionality and content of the previously defined pdo/php_pdo.h that has been specifically tailored for your database. If your driver requires the use of global variables they should be defined using the ZEND_BEGIN_MODULE_GLOBALS and ZEND_END_MODULE_GLOBALS macros. Macros are then used to access these variables. This macro is usually named PDO_SKEL_G(v) where v is global variable to be accessed. Consult the Zend programmer documentation for more information.

php_pdo_SKEL_int.h

  This header file typically contains type definitions and function declarations specific to the driver implementation. It also should contain the db specific definitions of a pdo_SKEL_handle and pdo_SKEL_stmt structures. These are the names of the private data structures that are then referenced by the driver_data members of the handle and statement structures.

### Optional Headers

Depending on the implementation details for a particular driver it may be necessary to include the following header:

    #include <zend_exceptions.h>

add a note User Contributed Notes
Preparation and Housekeeping
There are no user contributed notes for this page.
Fleshing out your skeleton Prerequisites

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST