php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
pdo_mysql.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: George Schlossnagle <george@omniti.com> |
14 | Johannes Schlueter <johannes@mysql.com> |
15 +----------------------------------------------------------------------+
16*/
17
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "php.h"
23#include "php_ini.h"
24#include "ext/standard/info.h"
25#include "ext/pdo/php_pdo.h"
27#include "php_pdo_mysql.h"
28#include "php_pdo_mysql_int.h"
29#include "pdo_mysql_arginfo.h"
30
31static zend_class_entry *pdo_mysql_ce;
32
33#ifdef COMPILE_DL_PDO_MYSQL
34#ifdef ZTS
36#endif
37ZEND_GET_MODULE(pdo_mysql)
38#endif
39
41
42/*
43 The default socket location is sometimes defined by configure.
44 With libmysql `mysql_config --socket` will fill PDO_MYSQL_UNIX_ADDR
45 and the user can use --with-mysql-sock=SOCKET which will fill
46 PHP_MYSQL_UNIX_SOCK_ADDR. If both aren't set we're using mysqlnd and use
47 /tmp/mysql.sock as default on *nix and NULL for Windows (default
48 named pipe name is set in mysqlnd).
49*/
50#ifndef PDO_MYSQL_UNIX_ADDR
51# ifdef PHP_MYSQL_UNIX_SOCK_ADDR
52# define PDO_MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR
53# else
54# ifndef PHP_WIN32
55# define PDO_MYSQL_UNIX_ADDR "/tmp/mysql.sock"
56# else
57# define PDO_MYSQL_UNIX_ADDR NULL
58# endif
59# endif
60#endif
61
62#ifdef PDO_USE_MYSQLND
64static MYSQLND * pdo_mysql_convert_zv_to_mysqlnd(zval * zv)
65{
66 if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), php_pdo_get_dbh_ce())) {
67 pdo_dbh_t * dbh = Z_PDO_DBH_P(zv);
68
69 ZEND_ASSERT(dbh);
70
71 if (dbh->driver != &pdo_mysql_driver) {
72 php_error_docref(NULL, E_WARNING, "Provided PDO instance is not using MySQL but %s", dbh->driver->driver_name);
73 return NULL;
74 }
75
76 return ((pdo_mysql_db_handle *)dbh->driver_data)->server;
77 }
78 return NULL;
79}
80
81static const MYSQLND_REVERSE_API pdo_mysql_reverse_api = {
83 pdo_mysql_convert_zv_to_mysqlnd
84};
85#endif
86
87/* Returns the number of SQL warnings during the execution of the last statement */
88PHP_METHOD(Pdo_Mysql, getWarningCount)
89{
90 pdo_dbh_t *dbh;
92
94
97
100}
101
102/* {{{ PHP_INI_BEGIN */
104#ifndef PHP_WIN32
105 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)
106#endif
107#if PDO_DBG_ENABLED
108 STD_PHP_INI_ENTRY("pdo_mysql.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
109#endif
111/* }}} */
112
113/* true global environment */
114
115/* {{{ PHP_MINIT_FUNCTION */
116static PHP_MINIT_FUNCTION(pdo_mysql)
117{
119
123#ifndef PDO_USE_MYSQLND
127#endif
137#if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
138 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SERVER_PUBLIC_KEY", (zend_long)PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY);
139#endif
141#ifdef PDO_USE_MYSQLND
142 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_VERIFY_SERVER_CERT", (zend_long)PDO_MYSQL_ATTR_SSL_VERIFY_SERVER_CERT);
143#endif
144#if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)
145 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE_DIRECTORY", (zend_long)PDO_MYSQL_ATTR_LOCAL_INFILE_DIRECTORY);
146#endif
147
148#ifdef PDO_USE_MYSQLND
149 mysqlnd_reverse_api_register_api(&pdo_mysql_reverse_api);
150#endif
151
152 pdo_mysql_ce = register_class_Pdo_Mysql(pdo_dbh_ce);
153 pdo_mysql_ce->create_object = pdo_dbh_new;
154
156 return FAILURE;
157 }
158
160}
161/* }}} */
162
163/* {{{ PHP_MSHUTDOWN_FUNCTION */
164static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
165{
167#ifdef PDO_USE_MYSQLND
169#endif
170
171 return SUCCESS;
172}
173/* }}} */
174
175/* {{{ PHP_MINFO_FUNCTION */
176static PHP_MINFO_FUNCTION(pdo_mysql)
177{
179
180 php_info_print_table_row(2, "PDO Driver for MySQL", "enabled");
181 php_info_print_table_row(2, "Client API version", mysql_get_client_info());
182
184
185#ifndef PHP_WIN32
187#endif
188}
189/* }}} */
190
191
192#if defined(PDO_USE_MYSQLND) && PDO_DBG_ENABLED
193/* {{{ PHP_RINIT_FUNCTION */
194static PHP_RINIT_FUNCTION(pdo_mysql)
195{
196 if (PDO_MYSQL_G(debug)) {
198 if (!dbg) {
199 return FAILURE;
200 }
201 dbg->m->set_mode(dbg, PDO_MYSQL_G(debug));
203 }
204
205 return SUCCESS;
206}
207/* }}} */
208
209/* {{{ PHP_RSHUTDOWN_FUNCTION */
210static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
211{
213 PDO_DBG_ENTER("RSHUTDOWN");
214 if (dbg) {
215 dbg->m->close(dbg);
216 dbg->m->free_handle(dbg);
218 }
219
220 return SUCCESS;
221}
222/* }}} */
223#endif
224
225/* {{{ PHP_GINIT_FUNCTION */
226static PHP_GINIT_FUNCTION(pdo_mysql)
227{
228#if defined(COMPILE_DL_PDO_MYSQL) && defined(ZTS)
230#endif
231#ifndef PHP_WIN32
232 pdo_mysql_globals->default_socket = NULL;
233#endif
234#if PDO_DBG_ENABLED
235 pdo_mysql_globals->debug = NULL; /* The actual string */
236 pdo_mysql_globals->dbg = NULL; /* The DBG object*/
237#endif
238}
239/* }}} */
240
241/* {{{ pdo_mysql_deps[] */
242static const zend_module_dep pdo_mysql_deps[] = {
243 ZEND_MOD_REQUIRED("pdo")
244#ifdef PDO_USE_MYSQLND
245 ZEND_MOD_REQUIRED("mysqlnd")
246#endif
248};
249/* }}} */
250
251/* {{{ pdo_mysql_module_entry */
254 pdo_mysql_deps,
255 "pdo_mysql",
256 NULL,
257 PHP_MINIT(pdo_mysql),
258 PHP_MSHUTDOWN(pdo_mysql),
259#if defined(PDO_USE_MYSQLND) && PDO_DBG_ENABLED
260 PHP_RINIT(pdo_mysql),
261 PHP_RSHUTDOWN(pdo_mysql),
262#else
263 NULL,
264 NULL,
265#endif
266 PHP_MINFO(pdo_mysql),
268 PHP_MODULE_GLOBALS(pdo_mysql),
269 PHP_GINIT(pdo_mysql),
270 NULL,
271 NULL,
273};
274/* }}} */
zval * zv
Definition ffi.c:3975
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define H(x, y, z)
Definition md5.c:146
const pdo_driver_t pdo_mysql_driver
MYSQLND_DEBUG * dbg
Definition mysqlnd.h:300
char * debug
Definition mysqlnd.h:298
PHPAPI const char * mysqlnd_debug_std_no_trace_funcs[]
PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char *skip_functions[])
#define mysql_warning_count(r)
#define mysql_get_client_info()
PHPAPI void mysqlnd_reverse_api_register_api(const MYSQLND_REVERSE_API *apiext)
struct st_mysqlnd_reverse_api MYSQLND_REVERSE_API
struct st_mysqlnd_connection MYSQLND
struct st_mysqlnd_debug MYSQLND_DEBUG
PDO_API void php_pdo_unregister_driver(const pdo_driver_t *driver)
Definition pdo.c:129
PDO_API zend_result php_pdo_register_driver(const pdo_driver_t *driver)
Definition pdo.c:113
PDO_API zend_result php_pdo_register_driver_specific_ce(const pdo_driver_t *driver, zend_class_entry *ce)
Definition pdo.c:140
PDO_API zend_class_entry * php_pdo_get_dbh_ce(void)
Definition pdo.c:56
zend_class_entry * pdo_dbh_ce
Definition pdo.c:34
zend_object * pdo_dbh_new(zend_class_entry *ce)
Definition pdo_dbh.c:1533
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PDO_MYSQL_UNIX_ADDR
Definition pdo_mysql.c:55
zend_module_entry pdo_mysql_module_entry
Definition pdo_mysql.c:252
#define PHP_GINIT
Definition php.h:397
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINFO
Definition php.h:396
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_RINIT
Definition php.h:394
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_GINIT_FUNCTION
Definition php.h:405
#define PHP_RSHUTDOWN
Definition php.h:395
#define PHP_RINIT_FUNCTION
Definition php.h:402
#define PHP_RSHUTDOWN_FUNCTION
Definition php.h:403
#define PHP_MINIT
Definition php.h:392
#define PHP_METHOD
Definition php.h:365
#define PHP_MODULE_GLOBALS
Definition php.h:408
#define PHP_INI_BEGIN
Definition php_ini.h:52
#define STD_PHP_INI_ENTRY
Definition php_ini.h:64
#define PHP_INI_SYSTEM
Definition php_ini.h:43
#define PHP_INI_END
Definition php_ini.h:53
char * default_socket
#define PDO_CONSTRUCT_CHECK
Definition php_pdo.h:64
#define REGISTER_PDO_CLASS_CONST_LONG(const_name, value)
Definition php_pdo.h:53
struct _pdo_dbh_t pdo_dbh_t
#define Z_PDO_DBH_P(zv)
#define PHP_PDO_MYSQL_VERSION
@ PDO_MYSQL_ATTR_SSL_CIPHER
@ PDO_MYSQL_ATTR_READ_DEFAULT_FILE
@ PDO_MYSQL_ATTR_SSL_CERT
@ PDO_MYSQL_ATTR_FOUND_ROWS
@ PDO_MYSQL_ATTR_DIRECT_QUERY
@ PDO_MYSQL_ATTR_MAX_BUFFER_SIZE
@ PDO_MYSQL_ATTR_READ_DEFAULT_GROUP
@ PDO_MYSQL_ATTR_COMPRESS
@ PDO_MYSQL_ATTR_LOCAL_INFILE
@ PDO_MYSQL_ATTR_USE_BUFFERED_QUERY
@ PDO_MYSQL_ATTR_IGNORE_SPACE
@ PDO_MYSQL_ATTR_SSL_KEY
@ PDO_MYSQL_ATTR_INIT_COMMAND
@ PDO_MYSQL_ATTR_SSL_CAPATH
@ PDO_MYSQL_ATTR_SSL_CA
@ PDO_MYSQL_ATTR_MULTI_STATEMENTS
#define PDO_MYSQL_G(v)
void * driver_data
pdo_driver_t * driver
const char * driver_name
#define ZEND_TSRMLS_CACHE_UPDATE()
Definition zend.h:69
#define ZEND_TSRMLS_CACHE_DEFINE()
Definition zend.h:68
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
Definition zend_API.h:268
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define ZEND_THIS
Definition zend_API.h:523
struct _zval_struct zval
#define E_WARNING
Definition zend_errors.h:24
#define UNREGISTER_INI_ENTRIES()
Definition zend_ini.h:204
#define REGISTER_INI_ENTRIES()
Definition zend_ini.h:203
#define DISPLAY_INI_ENTRIES()
Definition zend_ini.h:205
int32_t zend_long
Definition zend_long.h:42
#define ZEND_MOD_END
struct _zend_module_dep zend_module_dep
struct _zend_module_entry zend_module_entry
#define ZEND_MOD_REQUIRED(name)
#define STANDARD_MODULE_PROPERTIES_EX
#define STANDARD_MODULE_HEADER_EX
#define ZEND_ASSERT(c)
struct _zend_class_entry zend_class_entry
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define Z_OBJCE_P(zval_p)
@ FAILURE
Definition zend_types.h:61
#define IS_OBJECT
Definition zend_types.h:608