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: 32 43 74.4 %
Date: 2015-05-30 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-2015 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             : #ifdef ZTS
      36             : ZEND_TSRMLS_CACHE_DEFINE();
      37             : #endif
      38             : ZEND_GET_MODULE(pdo_mysql)
      39             : #endif
      40             : 
      41             : ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql)
      42             : 
      43             : /*
      44             :  The default socket location is sometimes defined by configure.
      45             :  With libmysql `mysql_config --socket` will fill PDO_MYSQL_UNIX_ADDR
      46             :  and the user can use --with-mysql-sock=SOCKET which will fill
      47             :  PDO_MYSQL_UNIX_ADDR. If both aren't set we're using mysqlnd and use
      48             :  /tmp/mysql.sock as default on *nix and NULL for Windows (default
      49             :  named pipe name is set in mysqlnd).
      50             : */
      51             : #ifndef PDO_MYSQL_UNIX_ADDR
      52             : # ifdef PHP_MYSQL_UNIX_SOCK_ADDR
      53             : #  define PDO_MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR
      54             : # else
      55             : #  if !PHP_WIN32
      56             : #   define PDO_MYSQL_UNIX_ADDR "/tmp/mysql.sock"
      57             : #  else
      58             : #   define PDO_MYSQL_UNIX_ADDR NULL
      59             : #  endif
      60             : # endif
      61             : #endif
      62             : 
      63             : #ifdef PDO_USE_MYSQLND
      64             : #include "ext/mysqlnd/mysqlnd_reverse_api.h"
      65           0 : static MYSQLND * pdo_mysql_convert_zv_to_mysqlnd(zval * zv)
      66             : {
      67           0 :         if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), php_pdo_get_dbh_ce())) {
      68           0 :                 pdo_dbh_t * dbh = Z_PDO_DBH_P(zv);
      69             : 
      70           0 :                 if (!dbh) {
      71           0 :                         php_error_docref(NULL, E_WARNING, "Failed to retrieve handle from object store");
      72           0 :                         return NULL;
      73             :                 }
      74             : 
      75           0 :                 if (dbh->driver != &pdo_mysql_driver) {
      76           0 :                         php_error_docref(NULL, E_WARNING, "Provided PDO instance is not using MySQL but %s", dbh->driver->driver_name);
      77           0 :                         return NULL;
      78             :                 }
      79             : 
      80           0 :                 return ((pdo_mysql_db_handle *)dbh->driver_data)->server;
      81             :         }
      82           0 :         return NULL;
      83             : }
      84             : 
      85             : static MYSQLND_REVERSE_API pdo_mysql_reverse_api = {
      86             :         &pdo_mysql_module_entry,
      87             :         pdo_mysql_convert_zv_to_mysqlnd
      88             : };
      89             : #endif
      90             : 
      91             : 
      92             : /* {{{ PHP_INI_BEGIN
      93             : */
      94             : PHP_INI_BEGIN()
      95             : #ifndef PHP_WIN32
      96             :         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)
      97             : #endif
      98             : #if PDO_DBG_ENABLED
      99             :         STD_PHP_INI_ENTRY("pdo_mysql.debug",  NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
     100             : #endif
     101             : PHP_INI_END()
     102             : /* }}} */
     103             : 
     104             : /* true global environment */
     105             : 
     106             : /* {{{ PHP_MINIT_FUNCTION
     107             :  */
     108       20952 : static PHP_MINIT_FUNCTION(pdo_mysql)
     109             : {
     110       20952 :         REGISTER_INI_ENTRIES();
     111             : 
     112       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (zend_long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
     113       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (zend_long)PDO_MYSQL_ATTR_LOCAL_INFILE);
     114       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (zend_long)PDO_MYSQL_ATTR_INIT_COMMAND);
     115             : #ifndef PDO_USE_MYSQLND
     116             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MAX_BUFFER_SIZE", (zend_long)PDO_MYSQL_ATTR_MAX_BUFFER_SIZE);
     117             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_FILE", (zend_long)PDO_MYSQL_ATTR_READ_DEFAULT_FILE);
     118             :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_GROUP", (zend_long)PDO_MYSQL_ATTR_READ_DEFAULT_GROUP);
     119             : #endif
     120       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_COMPRESS", (zend_long)PDO_MYSQL_ATTR_COMPRESS);
     121       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (zend_long)PDO_MYSQL_ATTR_DIRECT_QUERY);
     122       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (zend_long)PDO_MYSQL_ATTR_FOUND_ROWS);
     123       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (zend_long)PDO_MYSQL_ATTR_IGNORE_SPACE);
     124       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_KEY", (zend_long)PDO_MYSQL_ATTR_SSL_KEY);
     125       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CERT", (zend_long)PDO_MYSQL_ATTR_SSL_CERT);
     126       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (zend_long)PDO_MYSQL_ATTR_SSL_CA);
     127       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (zend_long)PDO_MYSQL_ATTR_SSL_CAPATH);
     128       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (zend_long)PDO_MYSQL_ATTR_SSL_CIPHER);
     129             : #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
     130       20952 :          REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SERVER_PUBLIC_KEY", (zend_long)PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY);
     131             : #endif
     132       20952 :         REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MULTI_STATEMENTS", (zend_long)PDO_MYSQL_ATTR_MULTI_STATEMENTS);
     133             : 
     134             : #ifdef PDO_USE_MYSQLND
     135       20952 :         mysqlnd_reverse_api_register_api(&pdo_mysql_reverse_api);
     136             : #endif
     137             : 
     138       20952 :         return php_pdo_register_driver(&pdo_mysql_driver);
     139             : }
     140             : /* }}} */
     141             : 
     142             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     143             :  */
     144       20988 : static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
     145             : {
     146       20988 :         php_pdo_unregister_driver(&pdo_mysql_driver);
     147             : #if PDO_USE_MYSQLND
     148       20988 :         UNREGISTER_INI_ENTRIES();
     149             : #endif
     150             : 
     151       20988 :         return SUCCESS;
     152             : }
     153             : /* }}} */
     154             : 
     155             : /* {{{ PHP_MINFO_FUNCTION
     156             :  */
     157         142 : static PHP_MINFO_FUNCTION(pdo_mysql)
     158             : {
     159         142 :         php_info_print_table_start();
     160             : 
     161         142 :         php_info_print_table_header(2, "PDO Driver for MySQL", "enabled");
     162         142 :         php_info_print_table_row(2, "Client API version", mysql_get_client_info());
     163             : 
     164         142 :         php_info_print_table_end();
     165             : 
     166             : #ifndef PHP_WIN32
     167         142 :         DISPLAY_INI_ENTRIES();
     168             : #endif
     169         142 : }
     170             : /* }}} */
     171             : 
     172             : 
     173             : #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
     174             : /* {{{ PHP_RINIT_FUNCTION
     175             :  */
     176             : static PHP_RINIT_FUNCTION(pdo_mysql)
     177             : {
     178             :         if (PDO_MYSQL_G(debug)) {
     179             :                 MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs);
     180             :                 if (!dbg) {
     181             :                         return FAILURE;
     182             :                 }
     183             :                 dbg->m->set_mode(dbg, PDO_MYSQL_G(debug));
     184             :                 PDO_MYSQL_G(dbg) = dbg;
     185             :         }
     186             : 
     187             :         return SUCCESS;
     188             : }
     189             : /* }}} */
     190             : 
     191             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     192             :  */
     193             : static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
     194             : {
     195             :         MYSQLND_DEBUG *dbg = PDO_MYSQL_G(dbg);
     196             :         PDO_DBG_ENTER("RSHUTDOWN");
     197             :         if (dbg) {
     198             :                 dbg->m->close(dbg);
     199             :                 dbg->m->free_handle(dbg);
     200             :                 PDO_MYSQL_G(dbg) = NULL;
     201             :         }
     202             : 
     203             :         return SUCCESS;
     204             : }
     205             : /* }}} */
     206             : #endif
     207             : 
     208             : /* {{{ PHP_GINIT_FUNCTION
     209             :  */
     210       20952 : static PHP_GINIT_FUNCTION(pdo_mysql)
     211             : {
     212             : #if defined(COMPILE_DL_PDO_MYSQL) && defined(ZTS)
     213             : ZEND_TSRMLS_CACHE_UPDATE();
     214             : #endif
     215             : #ifndef PHP_WIN32
     216       20952 :         pdo_mysql_globals->default_socket = NULL;
     217             : #endif
     218             : #if PDO_DBG_ENABLED
     219             :         pdo_mysql_globals->debug = NULL;     /* The actual string */
     220             :         pdo_mysql_globals->dbg = NULL;       /* The DBG object*/
     221             : #endif
     222       20952 : }
     223             : /* }}} */
     224             : 
     225             : /* {{{ pdo_mysql_functions[] */
     226             : const zend_function_entry pdo_mysql_functions[] = {
     227             :         PHP_FE_END
     228             : };
     229             : /* }}} */
     230             : 
     231             : /* {{{ pdo_mysql_deps[] */
     232             : #if ZEND_MODULE_API_NO >= 20050922
     233             : static const zend_module_dep pdo_mysql_deps[] = {
     234             :         ZEND_MOD_REQUIRED("pdo")
     235             : #ifdef PDO_USE_MYSQLND
     236             :         ZEND_MOD_REQUIRED("mysqlnd")
     237             : #endif
     238             :         ZEND_MOD_END
     239             : };
     240             : #endif
     241             : /* }}} */
     242             : 
     243             : /* {{{ pdo_mysql_module_entry */
     244             : zend_module_entry pdo_mysql_module_entry = {
     245             :         STANDARD_MODULE_HEADER_EX, NULL,
     246             :         pdo_mysql_deps,
     247             :         "pdo_mysql",
     248             :         pdo_mysql_functions,
     249             :         PHP_MINIT(pdo_mysql),
     250             :         PHP_MSHUTDOWN(pdo_mysql),
     251             : #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
     252             :         PHP_RINIT(pdo_mysql),
     253             :         PHP_RSHUTDOWN(pdo_mysql),
     254             : #else
     255             :         NULL,
     256             :         NULL,
     257             : #endif
     258             :         PHP_MINFO(pdo_mysql),
     259             :         PHP_PDO_MYSQL_VERSION,
     260             :         PHP_MODULE_GLOBALS(pdo_mysql),
     261             :         PHP_GINIT(pdo_mysql),
     262             :         NULL,
     263             :         NULL,
     264             :         STANDARD_MODULE_PROPERTIES_EX
     265             : };
     266             : /* }}} */
     267             : 
     268             : 
     269             : /*
     270             :  * Local variables:
     271             :  * tab-width: 4
     272             :  * c-basic-offset: 4
     273             :  * End:
     274             :  * vim600: noet sw=4 ts=4 fdm=marker
     275             :  * vim<600: noet sw=4 ts=4
     276             :  */

Generated by: LCOV version 1.10

Generated at Sat, 30 May 2015 05:52:53 +0000 (2 hours ago)

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