<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >pdo_dbh_t definition</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="PDO Driver How-To" HREF="internals.pdo.html"><LINK REL="PREVIOUS" TITLE="Packaging and distribution" HREF="internals.pdo.packaging.html"><LINK REL="NEXT" TITLE="pdo_stmt_t definition" HREF="internals.pdo.pdo_stmt_t.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="internals.pdo.packaging.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Capítulo 45. PDO Driver How-To</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="internals.pdo.pdo_stmt_t.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="internals.pdo.pdo-dbh-t" >pdo_dbh_t definition</A ></H1 ><P > All fields should be treated as read-only by the driver, unless explicitly stated otherwise. </P ><DIV CLASS="figure" ><A NAME="AEN246558" ></A ><P ><B >Figura 45-1. pdo_dbh_t</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="c" >/* represents a connection to a database */ struct _pdo_dbh_t { /* driver specific methods */ struct pdo_dbh_methods *methods; <A NAME="internals.pdo.dbh.co.methods" ><IMG SRC="../images/callouts/1.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(1)"></A > /* driver specific data */ void *driver_data; <A NAME="internals.pdo.dbh.co.driver-data" ><IMG SRC="../images/callouts/2.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(2)"></A > /* credentials */ char *username, *password; <A NAME="internals.pdo.dbh.co.credentials" ><IMG SRC="../images/callouts/3.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(3)"></A > /* if true, then data stored and pointed at by this handle must all be * persistently allocated */ unsigned is_persistent:1; <A NAME="internals.pdo.dbh.co.is-persist" ><IMG SRC="../images/callouts/4.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(4)"></A > /* if true, driver should act as though a COMMIT were executed between * each executed statement; otherwise, COMMIT must be carried out manually * */ unsigned auto_commit:1; <A NAME="internals.pdo.dbh.co.auto-commit" ><IMG SRC="../images/callouts/5.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(5)"></A > /* if true, the driver requires that memory be allocated explicitly for * the columns that are returned */ unsigned alloc_own_columns:1; <A NAME="internals.pdo.dbh.co.alloc-own" ><IMG SRC="../images/callouts/6.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(6)"></A > /* if true, commit or rollBack is allowed to be called */ unsigned in_txn:1; /* max length a single character can become after correct quoting */ unsigned max_escaped_char_length:3; <A NAME="internals.pdo.dbh.co.max-esc" ><IMG SRC="../images/callouts/7.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(7)"></A > /* data source string used to open this handle */ const char *data_source; <A NAME="internals.pdo.dbh.co.dsn" ><IMG SRC="../images/callouts/8.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(8)"></A > unsigned long data_source_len; /* the global error code. */ pdo_error_type error_code; <A NAME="internals.pdo.dbh.co.error-code" ><IMG SRC="../images/callouts/9.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(9)"></A > enum pdo_case_conversion native_case<A NAME="internals.pdo.dbh.co-ncase" ><IMG SRC="../images/callouts/10.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(10)"></A >, desired_case; };</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="calloutlist" ><DL COMPACT="COMPACT" ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.methods" ><IMG SRC="../images/callouts/1.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(1)"></A ></DT ><DD > The driver <SPAN CLASS="emphasis" ><I CLASS="emphasis" >must</I ></SPAN > set this during <B CLASS="function" >SKEL_handle_factory()</B >. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.driver-data" ><IMG SRC="../images/callouts/2.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(2)"></A ></DT ><DD > This item is for use by the driver; the intended usage is to store a pointer (during <B CLASS="function" >SKEL_handle_factory()</B >) to whatever instance data is required to maintain a connection to the database. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.credentials" ><IMG SRC="../images/callouts/3.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(3)"></A ></DT ><DD > 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. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.is-persist" ><IMG SRC="../images/callouts/4.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(4)"></A ></DT ><DD > If this is set to 1, then any data that is referenced by the dbh, including whatever structure your driver allocates, <SPAN CLASS="emphasis" ><I CLASS="emphasis" >MUST</I ></SPAN > be allocated persistently. This is easy to achieve; rather than using the usual <B CLASS="function" >emalloc()</B > simply use <B CLASS="function" >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. </DD ><DD ><P > If, for whatever reason, your driver is not suitable to run persistently, you <SPAN CLASS="emphasis" ><I CLASS="emphasis" >MUST</I ></SPAN > check this flag in your <B CLASS="function" >SKEL_handle_factory()</B > and raise an appropriate error. </P ></DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.auto-commit" ><IMG SRC="../images/callouts/5.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(5)"></A ></DT ><DD > You should check this value in your <B CLASS="function" >SKEL_handle_doer()</B > and <B CLASS="function" >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. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.alloc-own" ><IMG SRC="../images/callouts/6.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(6)"></A ></DT ><DD > 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 CLASS="function" >SKEL_handle_factory()</B >. When set, PDO will call your <B CLASS="function" >SKEL_stmt_describer()</B > earlier that it would otherwise. This early call allows you to determine those buffer sizes and issue appropriate calls to the database client library. </DD ><DD ><P > 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 ></DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.max-esc" ><IMG SRC="../images/callouts/7.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(7)"></A ></DT ><DD > If your driver doesn't support native prepared statements (<CODE CLASS="parameter" >supports_placeholders</CODE > is set to <TT CLASS="constant" ><B >PDO_PLACEHOLDER_NONE</B ></TT >), 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 CLASS="function" >SKEL_handle_quoter()</B > function. This value is used to calculate the amount of buffer space required when PDO it executes the statement. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.dsn" ><IMG SRC="../images/callouts/8.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(8)"></A ></DT ><DD > 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 CLASS="function" >SKEL_handle_factory()</B >. Modifying this member should be avoided. If you do change it, you must ensure that <CODE CLASS="parameter" >data_source_len</CODE > is also correct. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co.error-code" ><IMG SRC="../images/callouts/9.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(9)"></A ></DT ><DD > 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 CLASS="function" >SKEL_handle_error()</B > when an error is detected, and have it set the error code. </DD ><DT ><A HREF="internals.pdo.pdo-dbh-t.html#internals.pdo.dbh.co-ncase" ><IMG SRC="../images/callouts/10.gif" HSPACE="0" VSPACE="0" BORDER="0" ALT="(10)"></A ></DT ><DD > Your driver should set this during <B CLASS="function" >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 <TT CLASS="constant" ><B >PDO_CASE_NATURAL</B ></TT > (this is actually the default). If the column names are always returned in upper case, set it to <TT CLASS="constant" ><B >PDO_CASE_UPPER</B ></TT >. If the column names are always return in lower case, set it to <TT CLASS="constant" ><B >PDO_CASE_LOWER</B ></TT >. The value you set it used to determine if PDO should perform case folding when the user sets the <TT CLASS="constant" ><B >PDO_ATTR_CASE</B ></TT > attribute. </DD ></DL ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="internals.pdo.packaging.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="internals.pdo.pdo_stmt_t.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Packaging and distribution</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="internals.pdo.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >pdo_stmt_t definition</TD ></TR ></TABLE ></DIV ></BODY ></HTML >