PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/pdo_mysql - pdo_mysql.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 31 42 73.8 %
Date: 2014-11-22 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2014 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: George Schlossnagle <george@omniti.com>                      |
      16             :   |         Johannes Schlueter <johannes@mysql.com>                      |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #include "php_ini.h"
      28             : #include "ext/standard/info.h"
      29             : #include "pdo/php_pdo.h"
      30             : #include "pdo/php_pdo_driver.h"
      31             : #include "php_pdo_mysql.h"
      32             : #include "php_pdo_mysql_int.h"
      33             : 
      34             : #ifdef COMPILE_DL_PDO_MYSQL
      35             : ZEND_GET_MODULE(pdo_mysql)
      36             : #endif
      37             : 
      38             : ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql)
      39             : 
      40             : /*
      41             :  The default socket location is sometimes defined by configure.
      42             :  With libmysql `mysql_config --socket` will fill PDO_MYSQL_UNIX_ADDR
      43             :  and the user can use --with-mysql-sock=SOCKET which will fill
      44             :  PDO_MYSQL_UNIX_ADDR. If both aren't set we're using mysqlnd and use
      45             :  /tmp/mysql.sock as default on *nix and NULL for Windows (default 
      46             :  named pipe name is set in mysqlnd).
      47             : */
      48             : #ifndef PDO_MYSQL_UNIX_ADDR
      49             : # ifdef PHP_MYSQL_UNIX_SOCK_ADDR
      50             : #  define PDO_MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR
      51             : # else
      52             : #  if !PHP_WIN32
      53             : #   define PDO_MYSQL_UNIX_ADDR "/tmp/mysql.sock"
      54             : #  else
      55             : #   define PDO_MYSQL_UNIX_ADDR NULL
      56             : #  endif
      57             : # endif
      58             : #endif
      59             : 
      60             : #ifdef PDO_USE_MYSQLND
      61             : #include "ext/mysqlnd/mysqlnd_reverse_api.h"
      62           0 : static MYSQLND * pdo_mysql_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
      63             : {
      64           0 :         if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), php_pdo_get_dbh_ce() TSRMLS_CC)) {
      65           0 :                 pdo_dbh_t * dbh = Z_PDO_DBH_P(zv);
      66             : 
      67           0 :                 if (!dbh) {
      68           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to retrieve handle from object store");
      69           0 :                         return NULL;
      70             :                 }
      71             : 
      72           0 :                 if (dbh->driver != &pdo_mysql_driver) {
      73           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided PDO instance is not using MySQL but %s", dbh->driver->driver_name);
      74           0 :                         return NULL;
      75             :                 }
      76             : 
      77           0 :                 return ((pdo_mysql_db_handle *)dbh->driver_data)->server;
      78             :         }
      79           0 :         return NULL;
      80             : }
      81             : 
      82             : static MYSQLND_REVERSE_API pdo_mysql_reverse_api = {
      83             :         &pdo_mysql_module_entry,
      84             :         pdo_mysql_convert_zv_to_mysqlnd
      85             : };
      86             : #endif
      87             : 
      88             : 
      89             : /* {{{ PHP_INI_BEGIN
      90             : */
      91             : PHP_INI_BEGIN()
      92             : #ifndef PHP_WIN32
      93             :         STD_PHP_INI_ENTRY("pdo_mysql.default_socket", PDO_MYSQL_UNIX_ADDR, PHP_INI_SYSTEM, OnUpdateStringUnempty, default_socket, zend_pdo_mysql_globals, pdo_mysql_globals)
      94             : #endif
      95             : #if PDO_DBG_ENABLED
      96             :         STD_PHP_INI_ENTRY("pdo_mysql.debug",  NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
      97             : #endif
      98             : PHP_INI_END()
      99             : /* }}} */
     100             : 
     101             : /* true global environment */           
     102             :                 
     103             : /* {{{ PHP_MINIT_FUNCTION
     104             :  */
     105       20507 : static PHP_MINIT_FUNCTION(pdo_mysql)
     106             : {
     107       20507 :         REGISTER_INI_ENTRIES();
     108             : 
     109       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (zend_long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
     110       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (zend_long)PDO_MYSQL_ATTR_LOCAL_INFILE);     
     111       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (zend_long)PDO_MYSQL_ATTR_INIT_COMMAND);
     112             : #ifndef PDO_USE_MYSQLND
     113             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MAX_BUFFER_SIZE", (zend_long)PDO_MYSQL_ATTR_MAX_BUFFER_SIZE);
     114             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_FILE", (zend_long)PDO_MYSQL_ATTR_READ_DEFAULT_FILE);
     115             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_GROUP", (zend_long)PDO_MYSQL_ATTR_READ_DEFAULT_GROUP);
     116             : #endif
     117       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_COMPRESS", (zend_long)PDO_MYSQL_ATTR_COMPRESS);
     118       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (zend_long)PDO_MYSQL_ATTR_DIRECT_QUERY);
     119       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (zend_long)PDO_MYSQL_ATTR_FOUND_ROWS);
     120       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (zend_long)PDO_MYSQL_ATTR_IGNORE_SPACE);
     121       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_KEY", (zend_long)PDO_MYSQL_ATTR_SSL_KEY);
     122       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CERT", (zend_long)PDO_MYSQL_ATTR_SSL_CERT);
     123       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (zend_long)PDO_MYSQL_ATTR_SSL_CA);
     124       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (zend_long)PDO_MYSQL_ATTR_SSL_CAPATH);
     125       20507 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (zend_long)PDO_MYSQL_ATTR_SSL_CIPHER);
     126             : #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
     127       20507 :          REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SERVER_PUBLIC_KEY", (zend_long)PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY);
     128             : #endif
     129             : 
     130             : 
     131             : #ifdef PDO_USE_MYSQLND
     132       20507 :         mysqlnd_reverse_api_register_api(&pdo_mysql_reverse_api TSRMLS_CC);
     133             : #endif
     134             : 
     135       20507 :         return php_pdo_register_driver(&pdo_mysql_driver);
     136             : }
     137             : /* }}} */
     138             : 
     139             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     140             :  */
     141       20541 : static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
     142             : {
     143       20541 :         php_pdo_unregister_driver(&pdo_mysql_driver);
     144             : #if PDO_USE_MYSQLND
     145       20541 :         UNREGISTER_INI_ENTRIES();
     146             : #endif
     147             : 
     148       20541 :         return SUCCESS;
     149             : }
     150             : /* }}} */
     151             : 
     152             : /* {{{ PHP_MINFO_FUNCTION
     153             :  */
     154         143 : static PHP_MINFO_FUNCTION(pdo_mysql)
     155             : {
     156         143 :         php_info_print_table_start();
     157             : 
     158         143 :         php_info_print_table_header(2, "PDO Driver for MySQL", "enabled");
     159         143 :         php_info_print_table_row(2, "Client API version", mysql_get_client_info());
     160             : 
     161         143 :         php_info_print_table_end();
     162             : 
     163             : #ifndef PHP_WIN32
     164         143 :         DISPLAY_INI_ENTRIES();
     165             : #endif
     166         143 : }
     167             : /* }}} */
     168             : 
     169             : 
     170             : #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
     171             : /* {{{ PHP_RINIT_FUNCTION
     172             :  */
     173             : static PHP_RINIT_FUNCTION(pdo_mysql)
     174             : {       
     175             :         if (PDO_MYSQL_G(debug)) {
     176             :                 MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
     177             :                 if (!dbg) {
     178             :                         return FAILURE;
     179             :                 }
     180             :                 dbg->m->set_mode(dbg, PDO_MYSQL_G(debug));
     181             :                 PDO_MYSQL_G(dbg) = dbg;
     182             :         }
     183             :         
     184             :         return SUCCESS;
     185             : }
     186             : /* }}} */
     187             : 
     188             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     189             :  */
     190             : static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
     191             : {
     192             :         MYSQLND_DEBUG *dbg = PDO_MYSQL_G(dbg);
     193             :         PDO_DBG_ENTER("RSHUTDOWN");
     194             :         if (dbg) {
     195             :                 dbg->m->close(dbg);
     196             :                 dbg->m->free_handle(dbg);
     197             :                 PDO_MYSQL_G(dbg) = NULL;
     198             :         }
     199             : 
     200             :         return SUCCESS;
     201             : }
     202             : /* }}} */
     203             : #endif
     204             : 
     205             : /* {{{ PHP_GINIT_FUNCTION
     206             :  */
     207       20507 : static PHP_GINIT_FUNCTION(pdo_mysql)
     208             : {
     209             : #ifndef PHP_WIN32
     210       20507 :         pdo_mysql_globals->default_socket = NULL;
     211             : #endif
     212             : #if PDO_DBG_ENABLED
     213             :         pdo_mysql_globals->debug = NULL;     /* The actual string */
     214             :         pdo_mysql_globals->dbg = NULL;       /* The DBG object*/
     215             : #endif
     216       20507 : }
     217             : /* }}} */
     218             : 
     219             : /* {{{ pdo_mysql_functions[] */
     220             : const zend_function_entry pdo_mysql_functions[] = {
     221             :         PHP_FE_END
     222             : };
     223             : /* }}} */
     224             : 
     225             : /* {{{ pdo_mysql_deps[] */
     226             : #if ZEND_MODULE_API_NO >= 20050922
     227             : static const zend_module_dep pdo_mysql_deps[] = {
     228             :         ZEND_MOD_REQUIRED("pdo")
     229             : #ifdef PDO_USE_MYSQLND
     230             :         ZEND_MOD_REQUIRED("mysqlnd")
     231             : #endif
     232             :         ZEND_MOD_END
     233             : };
     234             : #endif
     235             : /* }}} */
     236             : 
     237             : /* {{{ pdo_mysql_module_entry */
     238             : zend_module_entry pdo_mysql_module_entry = {
     239             :         STANDARD_MODULE_HEADER_EX, NULL,
     240             :         pdo_mysql_deps,
     241             :         "pdo_mysql",
     242             :         pdo_mysql_functions,
     243             :         PHP_MINIT(pdo_mysql),
     244             :         PHP_MSHUTDOWN(pdo_mysql),
     245             : #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
     246             :         PHP_RINIT(pdo_mysql),
     247             :         PHP_RSHUTDOWN(pdo_mysql),
     248             : #else
     249             :         NULL,
     250             :         NULL,
     251             : #endif
     252             :         PHP_MINFO(pdo_mysql),
     253             :         "1.0.2",
     254             :         PHP_MODULE_GLOBALS(pdo_mysql),
     255             :         PHP_GINIT(pdo_mysql),
     256             :         NULL,
     257             :         NULL,
     258             :         STANDARD_MODULE_PROPERTIES_EX
     259             : };
     260             : /* }}} */
     261             : 
     262             : 
     263             : /*
     264             :  * Local variables:
     265             :  * tab-width: 4
     266             :  * c-basic-offset: 4
     267             :  * End:
     268             :  * vim600: noet sw=4 ts=4 fdm=marker
     269             :  * vim<600: noet sw=4 ts=4
     270             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:21 +0000 (4 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.