Back to index

php5  5.3.10
Functions | Variables
pdo.c File Reference
#include <ctype.h>
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_pdo.h"
#include "php_pdo_driver.h"
#include "php_pdo_int.h"
#include "zend_exceptions.h"

Go to the source code of this file.

Functions

static PHP_GINIT_FUNCTION (pdo)
int php_pdo_list_entry (void)
PDO_API zend_class_entry * php_pdo_get_dbh_ce (void)
PDO_API zend_class_entry * php_pdo_get_exception (void)
PDO_API char * php_pdo_str_tolower_dup (const char *src, int len)
PDO_API zend_class_entry * php_pdo_get_exception_base (int root TSRMLS_DC)
 PHP_FUNCTION (pdo_drivers)
PDO_API int php_pdo_register_driver (pdo_driver_t *driver)
PDO_API void php_pdo_unregister_driver (pdo_driver_t *driver)
pdo_driver_tpdo_find_driver (const char *name, int namelen)
PDO_API int php_pdo_parse_data_source (const char *data_source, unsigned long data_source_len, struct pdo_data_src_parser *parsed, int nparams)
PDO_API char * php_pdo_int64_to_str (pdo_int64_t i64 TSRMLS_DC)
 PHP_MINIT_FUNCTION (pdo)
 PHP_MSHUTDOWN_FUNCTION (pdo)
 PHP_MINFO_FUNCTION (pdo)

Variables

static zend_class_entry * spl_ce_RuntimeException
HashTable pdo_driver_hash
static int le_ppdo
zend_class_entry * pdo_exception_ce
zend_class_entry * pdo_dbh_ce
zend_class_entry * pdo_dbstmt_ce
zend_class_entry * pdo_row_ce
const zend_function_entry pdo_functions []
zend_module_entry pdo_module_entry
static const char digit_vec [] = "0123456789"

Function Documentation

pdo_driver_t* pdo_find_driver ( const char *  name,
int  namelen 
)

Definition at line 206 of file pdo.c.

{
       pdo_driver_t **driver = NULL;
       
       zend_hash_find(&pdo_driver_hash, (char*)name, namelen, (void**)&driver);

       return driver ? *driver : NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( pdo_drivers  )

Definition at line 101 of file pdo.c.

{
       HashPosition pos;
       pdo_driver_t **pdriver;

       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }
       
       array_init(return_value);

       zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos);
       while (SUCCESS == zend_hash_get_current_data_ex(&pdo_driver_hash, (void**)&pdriver, &pos)) {
              add_next_index_stringl(return_value, (char*)(*pdriver)->driver_name, (*pdriver)->driver_name_len, 1);
              zend_hash_move_forward_ex(&pdo_driver_hash, &pos);
       }
}

Here is the call graph for this function:

static PHP_GINIT_FUNCTION ( pdo  ) [static]

Definition at line 175 of file pdo.c.

{
       pdo_globals->global_value = 0;
}
PHP_MINFO_FUNCTION ( pdo  )

Definition at line 396 of file pdo.c.

{
       HashPosition pos;
       char *drivers = NULL, *ldrivers = estrdup("");
       pdo_driver_t **pdriver;
       
       php_info_print_table_start();
       php_info_print_table_header(2, "PDO support", "enabled");

       zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos);
       while (SUCCESS == zend_hash_get_current_data_ex(&pdo_driver_hash, (void**)&pdriver, &pos)) {
              spprintf(&drivers, 0, "%s, %s", ldrivers, (*pdriver)->driver_name);
              zend_hash_move_forward_ex(&pdo_driver_hash, &pos);
              efree(ldrivers);
              ldrivers = drivers;
       }
       
       php_info_print_table_row(2, "PDO drivers", drivers ? drivers+2 : "");

       if (drivers) {
              efree(drivers);
       } else {
              efree(ldrivers);
       }

       php_info_print_table_end();

}

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( pdo  )

Definition at line 358 of file pdo.c.

Here is the call graph for this function:

Definition at line 387 of file pdo.c.

Here is the call graph for this function:

PDO_API zend_class_entry* php_pdo_get_dbh_ce ( void  )

Definition at line 57 of file pdo.c.

{
       return pdo_dbh_ce;
}
PDO_API zend_class_entry* php_pdo_get_exception ( void  )

Definition at line 62 of file pdo.c.

{
       return pdo_exception_ce;
}

Here is the caller graph for this function:

PDO_API zend_class_entry* php_pdo_get_exception_base ( int root  TSRMLS_DC)

Definition at line 74 of file pdo.c.

{
#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
       if (!root) {
              if (!spl_ce_RuntimeException) {
                     zend_class_entry **pce;

                     if (zend_hash_find(CG(class_table), "runtimeexception", sizeof("RuntimeException"), (void **) &pce) == SUCCESS) {
                            spl_ce_RuntimeException = *pce;
                            return *pce;
                     }
              } else {
                     return spl_ce_RuntimeException;
              }
       }
#endif
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
       return zend_exception_get_default();
#else
       return zend_exception_get_default(TSRMLS_C);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 317 of file pdo.c.

{
       char buffer[65];
       char outbuf[65] = "";
       register char *p;
       long long_val;
       char *dst = outbuf;

       if (i64 < 0) {
              i64 = -i64;
              *dst++ = '-';
       }

       if (i64 == 0) {
              *dst++ = '0';
              *dst++ = '\0';
              return estrdup(outbuf);
       }

       p = &buffer[sizeof(buffer)-1];
       *p = '\0';

       while ((pdo_uint64_t)i64 > (pdo_uint64_t)LONG_MAX) {
              pdo_uint64_t quo = (pdo_uint64_t)i64 / (unsigned int)10;
              unsigned int rem = (unsigned int)(i64 - quo*10U);
              *--p = digit_vec[rem];
              i64 = (pdo_int64_t)quo;
       }
       long_val = (long)i64;
       while (long_val != 0) {
              long quo = long_val / 10;
              *--p = digit_vec[(unsigned int)(long_val - quo * 10)];
              long_val = quo;
       }
       while ((*dst++ = *p++) != 0)
              ;
       *dst = '\0';
       return estrdup(outbuf);
}

Here is the caller graph for this function:

int php_pdo_list_entry ( void  )

Definition at line 49 of file pdo.c.

{
       return le_ppdo;
}

Here is the caller graph for this function:

PDO_API int php_pdo_parse_data_source ( const char *  data_source,
unsigned long  data_source_len,
struct pdo_data_src_parser parsed,
int  nparams 
)

Definition at line 215 of file pdo.c.

{
       int i, j;
       int valstart = -1;
       int semi = -1;
       int optstart = 0;
       int nlen;
       int n_matches = 0;
       int n_semicolumns = 0;

       i = 0;
       while (i < data_source_len) {
              /* looking for NAME= */

              if (data_source[i] == '\0') {
                     break;
              }

              if (data_source[i] != '=') {
                     ++i;
                     continue;
              }

              valstart = ++i;

              /* now we're looking for VALUE; or just VALUE<NUL> */
              semi = -1;
              n_semicolumns = 0;
              while (i < data_source_len) {
                     if (data_source[i] == '\0') {
                            semi = i++;
                            break;
                     }
                     if (data_source[i] == ';') {
                            if ((i + 1 >= data_source_len) || data_source[i+1] != ';') {
                                   semi = i++;
                                   break;
                            } else {
                                   n_semicolumns++; 
                                   i += 2;
                                   continue;
                            }
                     }
                     ++i;
              }

              if (semi == -1) {
                     semi = i;
              }

              /* find the entry in the array */
              nlen = valstart - optstart - 1;
              for (j = 0; j < nparams; j++) {
                     if (0 == strncmp(data_source + optstart, parsed[j].optname, nlen) && parsed[j].optname[nlen] == '\0') {
                            /* got a match */
                            if (parsed[j].freeme) {
                                   efree(parsed[j].optval);
                            }

                            if (n_semicolumns == 0) {
                                   parsed[j].optval = estrndup(data_source + valstart, semi - valstart - n_semicolumns);
                            } else {
                                   int vlen = semi - valstart;
                                   char *orig_val = data_source + valstart;
                                   char *new_val  = (char *) emalloc(vlen - n_semicolumns + 1);
                            
                                   parsed[j].optval = new_val;

                                   while (vlen && *orig_val) {
                                          *new_val = *orig_val;
                                          new_val++;

                                          if (*orig_val == ';') {
                                                 orig_val+=2; 
                                                 vlen-=2;
                                          } else {
                                                 orig_val++;
                                                 vlen--;
                                          }
                                   }
                                   *new_val = '\0';
                            }

                            parsed[j].freeme = 1;
                            ++n_matches;
                            break;
                     }
              }

              while (i < data_source_len && isspace(data_source[i])) {
                     i++;
              }

              optstart = i;
       }

       return n_matches;
}

Here is the caller graph for this function:

Definition at line 181 of file pdo.c.

{
       if (driver->api_version != PDO_DRIVER_API) {
              zend_error(E_ERROR, "PDO: driver %s requires PDO API version %ld; this is PDO version %d",
                     driver->driver_name, driver->api_version, PDO_DRIVER_API);
              return FAILURE;
       }
       if (!zend_hash_exists(&module_registry, "pdo", sizeof("pdo"))) {
              zend_error(E_ERROR, "You MUST load PDO before loading any PDO drivers");
              return FAILURE;      /* NOTREACHED */
       }

       return zend_hash_add(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len,
                     (void**)&driver, sizeof(pdo_driver_t *), NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PDO_API char* php_pdo_str_tolower_dup ( const char *  src,
int  len 
)

Definition at line 67 of file pdo.c.

{
       char *dest = emalloc(len + 1);
       zend_str_tolower_copy(dest, src, len);
       return dest;
}

Here is the call graph for this function:

Definition at line 197 of file pdo.c.

{
       if (!zend_hash_exists(&module_registry, "pdo", sizeof("pdo"))) {
              return;
       }

       zend_hash_del(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char digit_vec[] = "0123456789" [static]

Definition at line 316 of file pdo.c.

int le_ppdo [static]

Definition at line 47 of file pdo.c.

zend_class_entry* pdo_dbh_ce

Definition at line 97 of file pdo.c.

zend_class_entry * pdo_dbstmt_ce

Definition at line 97 of file pdo.c.

Definition at line 44 of file pdo.c.

zend_class_entry* pdo_exception_ce

Definition at line 55 of file pdo.c.

Initial value:

Definition at line 126 of file pdo.c.

zend_module_entry pdo_module_entry
Initial value:

Definition at line 144 of file pdo.c.

zend_class_entry * pdo_row_ce

Definition at line 97 of file pdo.c.

zend_class_entry* spl_ce_RuntimeException [static]

Definition at line 36 of file pdo.c.