Source of: /manual/en/internals2.pdo.preparation.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/internals2.pdo.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'internals2.pdo.preparation.php',
1 => 'Preparation and Housekeeping',
),
'up' =>
array (
0 => 'internals2.pdo.php',
1 => 'PDO Driver How-To',
),
'prev' =>
array (
0 => 'internals2.pdo.prerequisites.php',
1 => 'Prerequisites',
),
'next' =>
array (
0 => 'internals2.pdo.implementing.php',
1 => 'Fleshing out your skeleton',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="internals2.pdo.preparation" class="sect1">
<h2 class="title">Preparation and Housekeeping</h2>
<div id="internals2.pdo.preparation.layout" class="sect2">
<h3 class="title">Source directory layout</h3>
<p class="para">
The source directory for a typical PDO driver is laid out as follows, where
<i>SKEL</i> 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.
</p>
<div class="example-contents screen">
<div class="cdata"><pre>
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/
</pre></div>
</div>
<p class="para">The contents of these files are defined later in this document.</p>
</div>
<div id="internals2.pdo.preparation.create-skel" class="sect2">
<h3 class="title">Creating a skeleton</h3>
<p class="para">
The easiest way to get started is to use the <strong class="command">ext_skel</strong>
shell script found in the PHP build tree in the <var class="filename">ext</var>
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 <var class="filename">ext</var> directory:
</p>
<div class="example-contents screen">
<div class="cdata"><pre>
./ext_skel --extname=pdo_SKEL
</pre></div>
</div>
<p class="para">
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.
</p>
</div>
<div id="internals2.pdo.preparation.std-includes" class="sect2">
<h3 class="title">Standard Includes</h3>
<div id="internals2.pdo.preparation.std-includes.build-specific" class="sect3">
<h4 class="title">Build Specific Headers</h4>
<p class="para">
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.
</p>
</div>
<div id="internals2.pdo.preparation.std-includes.php" class="sect3">
<h4 class="title">PHP Headers</h4>
<p class="para">
The following standard public php headers should be included in each
source module:
</p>
<ol type="1">
<li class="listitem">
<p class="para">php.h</p>
</li>
<li class="listitem">
<p class="para">php_ini.h</p>
</li>
<li class="listitem">
<p class="para">ext/standard/info.h</p>
</li>
</ol>
</div>
<div id="internals2.pdo.preparation.std-includes.pdo" class="sect3">
<h4 class="title">PDO Interface Headers</h4>
<p class="para">
The following standard public PDO header files are also included in each
source module:
</p>
<dl>
<dt class="varlistentry">
<span class="term">pdo/php_pdo.h</span>
</dt><dd class="listitem">
<p class="para">
This header file contains definitions of the initialization and shutdown
functions in the main driver as well as definitions of global PDO
variables.
</p>
</dd>
<dt class="varlistentry">
<span class="term">pdo/php_pdo_driver.h</span>
</dt><dd class="listitem">
<p class="para">
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.
</p>
</dd>
</dl>
</div>
<div id="internals2.pdo.preparation.std-headers.driver-spec" class="sect3">
<h4 class="title">Driver Specific Headers</h4>
<p class="para">
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:
</p>
<dl>
<dt class="varlistentry">
<span class="term">php_pdo_SKEL.h</span>
</dt><dd class="listitem">
<p class="para">
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.
</p>
</dd>
<dt class="varlistentry">
<span class="term">php_pdo_SKEL_int.h</span>
</dt><dd class="listitem">
<p class="para">
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.
</p>
</dd>
</dl>
</div>
<div id="internals2.pdo.preparation.std-headers.optional" class="sect3">
<h4 class="title">Optional Headers</h4>
<p class="para">
Depending on the implementation details for a particular driver it may be
necessary to include the following header:
</p>
<div class="example-contents programlisting">
<div class="ccode"><pre class="ccode">#include <zend_exceptions.h></pre>
</div>
</div>
</div>
</div>
</div><?php manual_footer(); ?>