php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysqli_warning.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: Georg Richter <georg@php.net> |
14 +----------------------------------------------------------------------+
15
16*/
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include <signal.h>
22
23#include "php.h"
24#include "php_mysqli_structs.h"
25#include "mysqli_priv.h"
26
27/* {{{ void php_clear_warnings() */
29{
31
32 while (w) {
33 n = w;
34 zval_ptr_dtor_str(&(w->reason));
35 zval_ptr_dtor_str(&(w->sqlstate));
36 w = w->next;
37 efree(n);
38 }
39}
40/* }}} */
41
42/* {{{ MYSQLI_WARNING *php_new_warning */
43static
44MYSQLI_WARNING *php_new_warning(zval * reason, int errorno)
45{
47
48 w = (MYSQLI_WARNING *)ecalloc(1, sizeof(MYSQLI_WARNING));
49
50 ZVAL_COPY(&w->reason, reason);
52
53 ZVAL_STRINGL(&(w->sqlstate), "HY000", sizeof("HY000") - 1);
54
55 w->errorno = errorno;
56
57 return w;
58}
59/* }}} */
60
61/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql) */
63{
64 MYSQLI_WARNING *w, *first = NULL, *prev = NULL;
66 zval row;
67
68 if (mysql->m->query(mysql, "SHOW WARNINGS", 13)) {
69 return NULL;
70 }
71
72 result = mysql->m->use_result(mysql);
73
74 for (;;) {
75 zval *entry;
76 int mysqli_errno;
77
79 if (Z_TYPE(row) != IS_ARRAY) {
80 zval_ptr_dtor(&row);
81 break;
82 }
83 zend_hash_internal_pointer_reset(Z_ARRVAL(row));
84 /* 0. we don't care about the first */
85 zend_hash_move_forward(Z_ARRVAL(row));
86
87 /* 1. Here comes the error no */
88 entry = zend_hash_get_current_data(Z_ARRVAL(row));
89 mysqli_errno = zval_get_long(entry);
90 zend_hash_move_forward(Z_ARRVAL(row));
91
92 /* 2. Here comes the reason */
93 entry = zend_hash_get_current_data(Z_ARRVAL(row));
94
95 w = php_new_warning(entry, mysqli_errno);
96 /*
97 Don't destroy entry, because the row destroy will decrease
98 the refcounter. Decreased twice then mysqlnd_free_result()
99 will crash, because it will try to access already freed memory.
100 */
101 if (!first) {
102 first = w;
103 }
104 if (prev) {
105 prev->next = (void *)w;
106 }
107 prev = w;
108
109 zval_ptr_dtor(&row);
110 }
111
113 return first;
114}
115/* }}} */
116
117/* {{{ bool mysqli_warning::next() */
119{
122
125 }
126
127 if (obj->ptr) {
129
130 if (w && w->next) {
131 w = w->next;
132 ((MYSQLI_RESOURCE *)(obj->ptr))->ptr = w;
134 }
135 }
137}
138/* }}} */
139
140/* {{{ property mysqli_warning_message */
141static zend_result mysqli_warning_message(mysqli_object *obj, zval *retval, bool quiet)
142{
144
145 if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
146 if (!quiet) {
147 zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
148 }
149
150 return FAILURE;
151 }
152
153 w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
154 ZVAL_COPY(retval, &w->reason);
155
156 return SUCCESS;
157}
158/* }}} */
159
160/* {{{ property mysqli_warning_sqlstate */
161static zend_result mysqli_warning_sqlstate(mysqli_object *obj, zval *retval, bool quiet)
162{
164
165 if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
166 if (!quiet) {
167 zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
168 }
169
170 return FAILURE;
171 }
172
173 w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
175
176 return SUCCESS;
177}
178/* }}} */
179
180/* {{{ property mysqli_warning_error */
181static zend_result mysqli_warning_errno(mysqli_object *obj, zval *retval, bool quiet)
182{
184
185 if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
186 if (!quiet) {
187 zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));
188 }
189
190 return FAILURE;
191 }
192
193 w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
195
196 return SUCCESS;
197}
198/* }}} */
199
201{
203
204 zend_throw_error(NULL, "Cannot directly construct mysqli_warning");
205}
206
207/* {{{ mysqli_warning_property_entries */
209 {"message", sizeof("message") - 1, mysqli_warning_message, NULL},
210 {"sqlstate", sizeof("sqlstate") - 1, mysqli_warning_sqlstate, NULL},
211 {"errno", sizeof("errno") - 1, mysqli_warning_errno, NULL},
212 {NULL, 0, NULL, NULL}
213};
214/* }}} */
prev(array|object &$array)
zend_long n
Definition ffi.c:4979
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
#define next(ls)
Definition minilua.c:2661
mysqli_errno(mysqli $mysql)
const mysqli_property_entry mysqli_warning_property_entries[]
void php_clear_warnings(MYSQLI_WARNING *w)
MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA *mysql)
#define mysqlnd_fetch_into(result, flags, ret_val)
Definition mysqlnd.h:103
@ MYSQLND_FETCH_NUM
#define MYSQL_RES
#define mysql_free_result(r)
struct st_mysqlnd_connection_data MYSQLND_CONN_DATA
#define PHP_METHOD
Definition php.h:365
struct st_mysqli_warning MYSQLI_WARNING
#define Z_MYSQLI_P(zv)
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check)
struct _mysqli_object mysqli_object
struct _mysqli_property_entry mysqli_property_entry
@ MYSQLI_STATUS_VALID
zend_string * name
Definition zend.h:149
zend_class_entry * ce
Definition zend_types.h:560
MYSQLI_WARNING * next
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define zend_parse_parameters_none()
Definition zend_API.h:353
#define RETURN_THROWS()
Definition zend_API.h:1060
#define ZEND_THIS
Definition zend_API.h:523
#define ZVAL_STRINGL(z, s, l)
Definition zend_API.h:952
#define RETURN_TRUE
Definition zend_API.h:1059
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define efree(ptr)
Definition zend_alloc.h:155
struct _zval_struct zval
#define convert_to_string(op)
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZVAL_LONG(z, l)
#define IS_ARRAY
Definition zend_types.h:607
@ FAILURE
Definition zend_types.h:61
#define ZVAL_COPY(z, v)
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
#define Z_TYPE(zval)
Definition zend_types.h:659
#define Z_ARRVAL(zval)
Definition zend_types.h:986
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zval retval
bool result