Back to index

php5  5.3.10
php_mysqli_structs.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Georg Richter <georg@php.net>                                |
00016   +----------------------------------------------------------------------+
00017 
00018   $Id: php_mysqli_structs.h 321634 2012-01-01 13:15:04Z felipe $
00019 */
00020 
00021 #ifndef PHP_MYSQLI_STRUCTS_H
00022 #define PHP_MYSQLI_STRUCTS_H
00023 
00024 /* A little hack to prevent build break, when mysql is used together with
00025  * c-client, which also defines LIST.
00026  */
00027 #ifdef LIST
00028 #undef LIST
00029 #endif
00030 
00031 #ifndef TRUE
00032 #define TRUE 1
00033 #endif
00034 
00035 #ifndef FALSE
00036 #define FALSE 0
00037 #endif
00038 
00039 #ifdef MYSQLI_USE_MYSQLND
00040 #include "ext/mysqlnd/mysqlnd.h"
00041 #include "mysqli_mysqlnd.h"
00042 #else
00043 
00044 /*
00045   The libmysql headers (a PITA) also define it and there will be an warning.
00046   Undef it and later we might need to define it again.
00047 */
00048 #ifdef HAVE_MBRLEN
00049 #undef HAVE_MBRLEN
00050 #define WE_HAD_MBRLEN
00051 #endif
00052 #ifdef HAVE_MBSTATE_T
00053 #undef HAVE_MBSTATE_T
00054 #define WE_HAD_MBSTATE_T
00055 #endif
00056 
00057 #if defined(ulong) && !defined(HAVE_ULONG)
00058 #define HAVE_ULONG
00059 #endif
00060 
00061 #include <my_global.h>
00062 
00063 #if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN)
00064 #define HAVE_MBRLEN 1
00065 #endif
00066 
00067 #if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T)
00068 #define HAVE_MBSTATE_T 1
00069 #endif
00070 
00071 /*
00072   We need more than mysql.h because we need CHARSET_INFO in one place.
00073   This order has been borrowed from the ODBC driver. Nothing can be removed
00074   from the list of headers :(
00075 */
00076 
00077 #include <my_sys.h>
00078 #include <mysql.h>
00079 #include <errmsg.h>
00080 #include <my_list.h>
00081 #include <m_string.h>
00082 #include <mysqld_error.h>
00083 #include <my_list.h>
00084 #include <m_ctype.h>
00085 #include "mysqli_libmysql.h"
00086 #endif /* MYSQLI_USE_MYSQLND */
00087 
00088 
00089 #define MYSQLI_VERSION_ID          101009
00090 
00091 enum mysqli_status {
00092        MYSQLI_STATUS_UNKNOWN=0,
00093        MYSQLI_STATUS_CLEARED,
00094        MYSQLI_STATUS_INITIALIZED,
00095        MYSQLI_STATUS_VALID
00096 };
00097 
00098 typedef struct {
00099        char          *val;
00100        ulong         buflen;
00101        ulong         output_len;
00102        ulong         type;
00103 } VAR_BUFFER;
00104 
00105 typedef struct {
00106        unsigned int  var_cnt;
00107        VAR_BUFFER           *buf;
00108        zval                 **vars;
00109        char                 *is_null;
00110 } BIND_BUFFER;
00111 
00112 typedef struct {
00113        MYSQL_STMT    *stmt;
00114        BIND_BUFFER   param;
00115        BIND_BUFFER   result;
00116        char          *query;
00117 } MY_STMT;
00118 
00119 typedef struct {
00120        MYSQL                *mysql;
00121        char                 *hash_key;
00122        zval                 *li_read;
00123        php_stream           *li_stream;
00124        unsigned int  multi_query;
00125        zend_bool            persistent;
00126 #if defined(MYSQLI_USE_MYSQLND)
00127        int                         async_result_fetch_type;
00128 #endif
00129 } MY_MYSQL;
00130 
00131 typedef struct {
00132        int                  mode;
00133        int                  socket;
00134        FILE          *fp;
00135 } PROFILER;
00136 
00137 typedef struct {
00138        void                        *ptr;         /* resource: (mysql, result, stmt)   */
00139        void                        *info;        /* additional buffer                       */
00140        enum mysqli_status   status;              /* object status */
00141 } MYSQLI_RESOURCE;
00142 
00143 typedef struct _mysqli_object {
00144        zend_object          zo;
00145        void                        *ptr;
00146        HashTable                   *prop_handler;
00147 } mysqli_object; /* extends zend_object */
00148 
00149 typedef struct st_mysqli_warning MYSQLI_WARNING;
00150 
00151 struct st_mysqli_warning {
00152        zval   reason;
00153        zval   sqlstate;
00154        int           errorno;
00155        MYSQLI_WARNING       *next;
00156 };
00157 
00158 typedef struct _mysqli_property_entry {
00159        const char *pname;
00160        size_t pname_length;
00161        int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
00162        int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
00163 } mysqli_property_entry;
00164 
00165 #if !defined(MYSQLI_USE_MYSQLND)
00166 typedef struct {
00167        char   error_msg[LOCAL_INFILE_ERROR_LEN];
00168        void   *userdata;
00169 } mysqli_local_infile;
00170 #endif
00171 
00172 typedef struct {
00173        zend_ptr_stack free_links;
00174 } mysqli_plist_entry;
00175 
00176 #ifdef PHP_WIN32
00177 #define PHP_MYSQLI_API __declspec(dllexport)
00178 #define MYSQLI_LLU_SPEC "%I64u"
00179 #define MYSQLI_LL_SPEC "%I64d"
00180 #ifndef L64
00181 #define L64(x) x##i64
00182 #endif
00183 typedef __int64 my_longlong;
00184 #else
00185 # if defined(__GNUC__) && __GNUC__ >= 4
00186 #  define PHP_MYSQLI_API __attribute__ ((visibility("default")))
00187 # else
00188 #  define PHP_MYSQLI_API
00189 # endif
00190 /* we need this for PRIu64 and PRId64 */
00191 #include <inttypes.h>
00192 #define MYSQLI_LLU_SPEC "%" PRIu64
00193 #define MYSQLI_LL_SPEC "%" PRId64
00194 #ifndef L64
00195 #define L64(x) x##LL
00196 #endif
00197 typedef int64_t my_longlong;
00198 #endif
00199 
00200 #ifdef ZTS
00201 #include "TSRM.h"
00202 #endif
00203 
00204 extern zend_class_entry *mysqli_link_class_entry;
00205 extern zend_class_entry *mysqli_stmt_class_entry;
00206 extern zend_class_entry *mysqli_result_class_entry;
00207 extern zend_class_entry *mysqli_driver_class_entry;
00208 extern zend_class_entry *mysqli_warning_class_entry;
00209 extern zend_class_entry *mysqli_exception_class_entry;
00210 
00211 #define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval)  \
00212        ((mysqli_object *) zend_object_store_get_object(__zval TSRMLS_CC))->ptr = __ptr;
00213 
00214 #define MYSQLI_RETURN_RESOURCE(__ptr, __ce) \
00215        Z_TYPE_P(return_value) = IS_OBJECT; \
00216        (return_value)->value.obj = mysqli_objects_new(__ce TSRMLS_CC); \
00217        MYSQLI_REGISTER_RESOURCE_EX(__ptr, return_value)
00218 
00219 #define MYSQLI_REGISTER_RESOURCE(__ptr, __ce) \
00220 {\
00221        zval *object = getThis();\
00222        if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {\
00223               object = return_value;\
00224               Z_TYPE_P(object) = IS_OBJECT;\
00225               (object)->value.obj = mysqli_objects_new(__ce TSRMLS_CC);\
00226        }\
00227        MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
00228 }
00229 
00230 #define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
00231 { \
00232        MYSQLI_RESOURCE *my_res; \
00233        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
00234        if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
00235               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
00236               RETURN_NULL();\
00237        }\
00238        __ptr = (__type)my_res->ptr; \
00239        if (__check && my_res->status < __check) { \
00240               php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
00241               RETURN_NULL();\
00242        }\
00243 }
00244 
00245 #define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
00246 { \
00247        MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
00248        if (!(__ptr)->mysql) { \
00249               mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
00250               php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
00251               RETURN_NULL();\
00252        } \
00253 }
00254 
00255 #define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
00256 { \
00257        MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
00258        if (!(__ptr)->stmt) { \
00259               mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
00260               php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
00261               RETURN_NULL();\
00262        } \
00263 }
00264 
00265 
00266 #define MYSQLI_SET_STATUS(__id, __value) \
00267 { \
00268        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
00269        ((MYSQLI_RESOURCE *)intern->ptr)->status = __value; \
00270 } \
00271 
00272 #define MYSQLI_CLEAR_RESOURCE(__id) \
00273 { \
00274        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
00275        efree(intern->ptr); \
00276        intern->ptr = NULL; \
00277 }
00278 
00279 
00280 ZEND_BEGIN_MODULE_GLOBALS(mysqli)
00281        long                 default_link;
00282        long                 num_links;
00283        long                 max_links;
00284        long                 num_active_persistent;
00285        long                 num_inactive_persistent;
00286        long                 max_persistent;
00287        long                 allow_persistent;
00288        long                 cache_size;
00289        unsigned long default_port;
00290        char                 *default_host;
00291        char                 *default_user;
00292        char                 *default_socket;
00293        char                 *default_pw;
00294        long                 reconnect;
00295        long                 allow_local_infile;
00296        long                 strict;
00297        long                 error_no;
00298        char                 *error_msg;
00299        long                 report_mode;
00300        HashTable            *report_ht;
00301        unsigned long multi_query;
00302        unsigned long embedded;
00303 ZEND_END_MODULE_GLOBALS(mysqli)
00304 
00305 
00306 #ifdef ZTS
00307 #define MyG(v) TSRMG(mysqli_globals_id, zend_mysqli_globals *, v)
00308 #else
00309 #define MyG(v) (mysqli_globals.v)
00310 #endif
00311 
00312 #define my_estrdup(x) (x) ? estrdup(x) : NULL
00313 #define my_efree(x) if (x) efree(x)
00314 
00315 ZEND_EXTERN_MODULE_GLOBALS(mysqli)
00316 
00317 #endif /* PHP_MYSQLI_STRUCTS.H */
00318 
00319 
00320 /*
00321  * Local variables:
00322  * tab-width: 4
00323  * c-basic-offset: 4
00324  * indent-tabs-mode: t
00325  * End:
00326  * vim600: noet sw=4 ts=4 fdm=marker
00327  * vim<600: noet sw=4 ts=4
00328  */