php_pdo_mysql_int.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. | Wez Furlong <wez@php.net> |
  17. | Johannes Schlueter <johannes@mysql.com> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #ifndef PHP_PDO_MYSQL_INT_H
  21. #define PHP_PDO_MYSQL_INT_H
  22. #if defined(PDO_USE_MYSQLND)
  23. # include "ext/mysqlnd/mysqlnd.h"
  24. # include "ext/mysqlnd/mysqlnd_libmysql_compat.h"
  25. # define PDO_MYSQL_PARAM_BIND MYSQLND_PARAM_BIND
  26. #else
  27. # include <mysql.h>
  28. #if MYSQL_VERSION_ID >= 80000 && MYSQL_VERSION_ID < 100000
  29. typedef _Bool my_bool;
  30. #endif
  31. # define PDO_MYSQL_PARAM_BIND MYSQL_BIND
  32. #endif
  33. #if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007 || defined(MYSQL_USE_MYSQLND)
  34. # define PDO_MYSQL_HAS_CHARSET
  35. #endif
  36. #if defined(PDO_USE_MYSQLND) && PHP_DEBUG && !defined(PHP_WIN32)
  37. #define PDO_DBG_ENABLED 1
  38. #define PDO_DBG_INF(msg) do { if (dbg_skip_trace == FALSE) PDO_MYSQL_G(dbg)->m->log(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "info : ", (msg)); } while (0)
  39. #define PDO_DBG_ERR(msg) do { if (dbg_skip_trace == FALSE) PDO_MYSQL_G(dbg)->m->log(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "error: ", (msg)); } while (0)
  40. #define PDO_DBG_INF_FMT(...) do { if (dbg_skip_trace == FALSE) PDO_MYSQL_G(dbg)->m->log_va(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "info : ", __VA_ARGS__); } while (0)
  41. #define PDO_DBG_ERR_FMT(...) do { if (dbg_skip_trace == FALSE) PDO_MYSQL_G(dbg)->m->log_va(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "error: ", __VA_ARGS__); } while (0)
  42. #define PDO_DBG_ENTER(func_name) \
  43. zend_bool dbg_skip_trace = TRUE; \
  44. ((void) dbg_skip_trace); \
  45. if (PDO_MYSQL_G(dbg)) \
  46. dbg_skip_trace = !PDO_MYSQL_G(dbg)->m->func_enter(PDO_MYSQL_G(dbg), __LINE__, __FILE__, func_name, strlen(func_name));
  47. #define PDO_DBG_RETURN(value) do { if (PDO_MYSQL_G(dbg)) PDO_MYSQL_G(dbg)->m->func_leave(PDO_MYSQL_G(dbg), __LINE__, __FILE__, 0); return (value); } while (0)
  48. #define PDO_DBG_VOID_RETURN do { if (PDO_MYSQL_G(dbg)) PDO_MYSQL_G(dbg)->m->func_leave(PDO_MYSQL_G(dbg), __LINE__, __FILE__, 0); return; } while (0)
  49. #else
  50. #define PDO_DBG_ENABLED 0
  51. static inline void PDO_DBG_INF(char *msg) {}
  52. static inline void PDO_DBG_ERR(char *msg) {}
  53. static inline void PDO_DBG_INF_FMT(char *format, ...) {}
  54. static inline void PDO_DBG_ERR_FMT(char *format, ...) {}
  55. static inline void PDO_DBG_ENTER(char *func_name) {}
  56. #define PDO_DBG_RETURN(value) return (value)
  57. #define PDO_DBG_VOID_RETURN return;
  58. #endif
  59. #if defined(PDO_USE_MYSQLND)
  60. #include "ext/mysqlnd/mysqlnd_debug.h"
  61. #endif
  62. ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
  63. #ifndef PHP_WIN32
  64. char *default_socket;
  65. #endif
  66. #if PDO_DBG_ENABLED
  67. char *debug; /* The actual string */
  68. MYSQLND_DEBUG *dbg; /* The DBG object */
  69. #endif
  70. #if defined(PHP_WIN32) && !PDO_DBG_ENABLED
  71. /* dummy member so we get at least one member in the struct
  72. * and avoids build errors.
  73. */
  74. void *dummymemmber;
  75. #endif
  76. ZEND_END_MODULE_GLOBALS(pdo_mysql)
  77. ZEND_EXTERN_MODULE_GLOBALS(pdo_mysql)
  78. #define PDO_MYSQL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pdo_mysql, v)
  79. #if defined(ZTS) && defined(COMPILE_DL_PDO_MYSQL)
  80. ZEND_TSRMLS_CACHE_EXTERN()
  81. #endif
  82. typedef struct {
  83. const char *file;
  84. int line;
  85. unsigned int errcode;
  86. char *errmsg;
  87. } pdo_mysql_error_info;
  88. /* stuff we use in a mySQL database handle */
  89. typedef struct {
  90. MYSQL *server;
  91. unsigned assume_national_character_set_strings:1;
  92. unsigned attached:1;
  93. unsigned buffered:1;
  94. unsigned emulate_prepare:1;
  95. unsigned fetch_table_names:1;
  96. #if !PDO_USE_MYSQLND
  97. zend_ulong max_buffer_size;
  98. #endif
  99. pdo_mysql_error_info einfo;
  100. } pdo_mysql_db_handle;
  101. typedef struct {
  102. MYSQL_FIELD *def;
  103. } pdo_mysql_column;
  104. typedef struct {
  105. pdo_mysql_db_handle *H;
  106. MYSQL_RES *result;
  107. const MYSQL_FIELD *fields;
  108. MYSQL_ROW current_data;
  109. #if PDO_USE_MYSQLND
  110. const size_t *current_lengths;
  111. #else
  112. zend_long *current_lengths;
  113. #endif
  114. pdo_mysql_error_info einfo;
  115. #if PDO_USE_MYSQLND
  116. MYSQLND_STMT *stmt;
  117. #else
  118. MYSQL_STMT *stmt;
  119. #endif
  120. int num_params;
  121. PDO_MYSQL_PARAM_BIND *params;
  122. #ifndef PDO_USE_MYSQLND
  123. my_bool *in_null;
  124. zend_ulong *in_length;
  125. #endif
  126. PDO_MYSQL_PARAM_BIND *bound_result;
  127. my_bool *out_null;
  128. zend_ulong *out_length;
  129. unsigned int params_given;
  130. unsigned max_length:1;
  131. } pdo_mysql_stmt;
  132. extern const pdo_driver_t pdo_mysql_driver;
  133. extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
  134. #define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__)
  135. #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__)
  136. extern const struct pdo_stmt_methods mysql_stmt_methods;
  137. enum {
  138. PDO_MYSQL_ATTR_USE_BUFFERED_QUERY = PDO_ATTR_DRIVER_SPECIFIC,
  139. PDO_MYSQL_ATTR_LOCAL_INFILE,
  140. PDO_MYSQL_ATTR_INIT_COMMAND,
  141. #ifndef PDO_USE_MYSQLND
  142. PDO_MYSQL_ATTR_READ_DEFAULT_FILE,
  143. PDO_MYSQL_ATTR_READ_DEFAULT_GROUP,
  144. PDO_MYSQL_ATTR_MAX_BUFFER_SIZE,
  145. #endif
  146. PDO_MYSQL_ATTR_COMPRESS,
  147. PDO_MYSQL_ATTR_DIRECT_QUERY,
  148. PDO_MYSQL_ATTR_FOUND_ROWS,
  149. PDO_MYSQL_ATTR_IGNORE_SPACE,
  150. PDO_MYSQL_ATTR_SSL_KEY,
  151. PDO_MYSQL_ATTR_SSL_CERT,
  152. PDO_MYSQL_ATTR_SSL_CA,
  153. PDO_MYSQL_ATTR_SSL_CAPATH,
  154. PDO_MYSQL_ATTR_SSL_CIPHER,
  155. #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
  156. PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY,
  157. #endif
  158. PDO_MYSQL_ATTR_MULTI_STATEMENTS,
  159. #ifdef PDO_USE_MYSQLND
  160. PDO_MYSQL_ATTR_SSL_VERIFY_SERVER_CERT,
  161. #endif
  162. };
  163. #endif