Source of: /manual/en/internals2.pdo.pdo-dbh-t.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.pdo-dbh-t.php',
1 => 'pdo_dbh_t definition',
),
'up' =>
array (
0 => 'internals2.pdo.php',
1 => 'PDO Driver How-To',
),
'prev' =>
array (
0 => 'internals2.pdo.packaging.php',
1 => 'Packaging and distribution',
),
'next' =>
array (
0 => 'internals2.pdo.pdo-stmt-t.php',
1 => 'pdo_stmt_t definition',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="internals2.pdo.pdo-dbh-t" class="sect1">
<h2 class="title">pdo_dbh_t definition</h2>
<p class="para">
All fields should be treated as read-only by the driver, unless explicitly
stated otherwise.
</p>
<div class="figure">
<h1 class="title">pdo_dbh_t</h1>
<div class="example-contents programlisting"><br />
/* represents a connection to a database */<br />
struct _pdo_dbh_t {<br />
/* driver specific methods */<br />
struct pdo_dbh_methods *methods; <a name="internals2.pdo.dbh.co.methods" id="internals2.pdo.dbh.co.methods">*</a><br />
/* driver specific data */<br />
void *driver_data; <a name="internals2.pdo.dbh.co.driver-data" id="internals2.pdo.dbh.co.driver-data">**</a><br />
<br />
/* credentials */<br />
char *username, *password; <a name="internals2.pdo.dbh.co.credentials" id="internals2.pdo.dbh.co.credentials">***</a><br />
<br />
/* if true, then data stored and pointed at by this handle must all be<br />
* persistently allocated */<br />
unsigned is_persistent:1; <a name="internals2.pdo.dbh.co.is-persist" id="internals2.pdo.dbh.co.is-persist">****</a><br />
<br />
/* if true, driver should act as though a COMMIT were executed between<br />
* each executed statement; otherwise, COMMIT must be carried out manually<br />
* */<br />
unsigned auto_commit:1; <a name="internals2.pdo.dbh.co.auto-commit" id="internals2.pdo.dbh.co.auto-commit">*****</a><br />
<br />
/* if true, the driver requires that memory be allocated explicitly for<br />
* the columns that are returned */<br />
unsigned alloc_own_columns:1; <a name="internals2.pdo.dbh.co.alloc-own" id="internals2.pdo.dbh.co.alloc-own">******</a><br />
<br />
/* if true, commit or rollBack is allowed to be called */<br />
unsigned in_txn:1; <br />
<br />
/* max length a single character can become after correct quoting */<br />
unsigned max_escaped_char_length:3; <a name="internals2.pdo.dbh.co.max-esc" id="internals2.pdo.dbh.co.max-esc">*******</a><br />
<br />
/* data source string used to open this handle */<br />
const char *data_source; <a name="internals2.pdo.dbh.co.dsn" id="internals2.pdo.dbh.co.dsn">********</a><br />
unsigned long data_source_len;<br />
<br />
/* the global error code. */<br />
pdo_error_type error_code; <a name="internals2.pdo.dbh.co.error-code" id="internals2.pdo.dbh.co.error-code">*********</a><br />
<br />
enum pdo_case_conversion native_case<a name="internals2.pdo.dbh.co-ncase" id="internals2.pdo.dbh.co-ncase">**********</a>, desired_case;<br />
};<br />
</div>
</div>
<table class="callout">
<tr><td><a href="#internals2.pdo.dbh.co.methods">*</a></td><td>
<p class="para">
The driver <em class="emphasis">must</em> set this during
<b>SKEL_handle_factory()</b>.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.driver-data">**</a></td><td>
<p class="para">
This item is for use by the driver; the intended usage is to store a
pointer (during <b>SKEL_handle_factory()</b>)
to whatever instance data is required to maintain a connection to
the database.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.credentials">***</a></td><td>
<p class="para">
The username and password that were passed into the PDO constructor.
The driver should use these values when it initiates a connection to the
database.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.is-persist">****</a></td><td>
<p class="para">
If this is set to 1, then any data that is referenced by the
dbh, including whatever structure your driver allocates,
<em class="emphasis">MUST</em> be allocated persistently. This is easy to
achieve; rather than using the usual <b>emalloc()</b> simply
use <b>pemalloc()</b> and pass the value of this flag as the
last parameter. Failure to use the appropriate kind of memory can lead
to serious memory faults, resulting (in the best case) a hard crash, and
in the worst case, an exploitable memory problem.
</p>
<p class="para">
If, for whatever reason, your driver is not suitable to run persistently,
you <em class="emphasis">MUST</em> check this flag in your
<b>SKEL_handle_factory()</b> and raise an appropriate error.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.auto-commit">*****</a></td><td>
<p class="para">
You should check this value in your <b>SKEL_handle_doer()</b>
and <b>SKEL_stmt_execute()</b> functions; if it evaluates to
true, you must attempt to commit the query now. Most database
implementations offer an auto-commit mode that handles this automatically.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.alloc-own">******</a></td><td>
<p class="para">
If your database client library API operates by fetching data into a
caller-supplied buffer, you should set this flag to 1 during your
<b>SKEL_handle_factory()</b>. When set, PDO will call your
<b>SKEL_stmt_describer()</b> earlier than it would
otherwise. This early call allows you to determine those buffer sizes
and issue appropriate calls to the database client library.
</p>
<p class="para">
If your database client library API simply returns pointers to its own
internal buffers for you to copy after each fetch call, you should leave
this value set to 0.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.max-esc">*******</a></td><td>
<p class="para">
If your driver doesn't support native prepared statements
(<i><tt class="parameter">supports_placeholders</tt></i>
is set to
<b><tt class="constant">PDO_PLACEHOLDER_NONE</tt></b>), you must set
this value to the maximum length that can be taken up by a single
character when it is quoted by your
<b>SKEL_handle_quoter()</b> function. This value is used to
calculate the amount of buffer space required when PDO executes the
statement.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.dsn">********</a></td><td>
<p class="para">
This holds the value of the DSN that was passed into the PDO
constructor. If your driver implementation needed to modify the DSN for
whatever reason, it should update this member during
<b>SKEL_handle_factory()</b>. Modifying this member should
be avoided. If you do change it, you must ensure that
<i><tt class="parameter">data_source_len</tt></i>
is also correct.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co.error-code">*********</a></td><td>
<p class="para">
Whenever an error occurs during a call to one of your driver methods,
you should set this member to the SQLSTATE code that best describes the
error and return an error. In this HOW-TO, the suggested practice is to
call <b>SKEL_handle_error()</b> when an error is detected,
and have it set the error code.
</p>
</td></tr>
<tr><td><a href="#internals2.pdo.dbh.co-ncase">**********</a></td><td>
<p class="para">
Your driver should set this during
<b>SKEL_handle_factory()</b>; the value should reflect how
the database returns the names of the columns in result sets. If the
name matches the case that was used in the query, set it to
<b><tt class="constant">PDO_CASE_NATURAL</tt></b> (this is actually the default).
If the column names are always returned in upper case, set it to
<b><tt class="constant">PDO_CASE_UPPER</tt></b>. If the column names are always
returned in lower case, set it to <b><tt class="constant">PDO_CASE_LOWER</tt></b>.
The value you set is used to determine if PDO should perform case
folding when the user sets the <b><tt class="constant">PDO_ATTR_CASE</tt></b>
attribute.
</p>
</td></tr>
</table>
</div><?php manual_footer(); ?>