php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysqli_exception.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
#include "
zend_exceptions.h
"
27
28
void
php_mysqli_throw_sql_exception
(
char
*
sqlstate
,
int
errorno,
char
*format, ...)
29
{
30
zval
sql_ex;
31
va_list
arg
;
32
char
*message;
33
34
va_start(
arg
, format);
35
vspprintf
(&message, 0, format,
arg
);
36
va_end(
arg
);
37
38
if
(!(
MyG
(
report_mode
) &
MYSQLI_REPORT_STRICT
)) {
39
php_error_docref
(
NULL
,
E_WARNING
,
"(%s/%d): %s"
,
sqlstate
, errorno, message);
40
efree
(message);
41
return
;
42
}
43
44
object_init_ex
(&sql_ex,
mysqli_exception_class_entry
);
45
46
if
(message) {
47
zend_update_property_string
(
48
mysqli_exception_class_entry
,
Z_OBJ
(sql_ex),
"message"
,
sizeof
(
"message"
) - 1, message);
49
}
50
51
if
(
sqlstate
) {
52
zend_update_property_string
(
53
mysqli_exception_class_entry
,
Z_OBJ
(sql_ex),
"sqlstate"
,
sizeof
(
"sqlstate"
) - 1,
sqlstate
);
54
}
else
{
55
zend_update_property_string
(
56
mysqli_exception_class_entry
,
Z_OBJ
(sql_ex),
"sqlstate"
,
sizeof
(
"sqlstate"
) - 1,
"00000"
);
57
}
58
59
efree
(message);
60
zend_update_property_long
(
mysqli_exception_class_entry
,
Z_OBJ
(sql_ex),
"code"
,
sizeof
(
"code"
) - 1, errorno);
61
62
zend_throw_exception_object
(&sql_ex);
63
}
64
65
PHP_METHOD
(
mysqli_sql_exception
, getSqlState)
66
{
67
zval
*prop;
68
zval
rv
;
69
70
ZEND_PARSE_PARAMETERS_NONE
();
71
72
prop =
zend_read_property
(
mysqli_exception_class_entry
,
Z_OBJ_P
(
ZEND_THIS
),
"sqlstate"
,
sizeof
(
"sqlstate"
)-1, 1, &
rv
);
73
ZVAL_DEREF
(prop);
74
zend_string
*str = zval_get_string(prop);
75
76
RETURN_STR
(str);
77
}
mysqli_sql_exception
Definition
mysqli.stub.php:1327
arg
zval * arg
Definition
ffi.c:3975
NULL
#define NULL
Definition
gdcache.h:45
php_error_docref
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition
main.c:1173
mysqli_exception_class_entry
zend_class_entry * mysqli_exception_class_entry
Definition
mysqli.c:71
php_mysqli_throw_sql_exception
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format,...)
Definition
mysqli_exception.c:28
mysqli_priv.h
MYSQLI_REPORT_STRICT
#define MYSQLI_REPORT_STRICT
Definition
mysqli_priv.h:105
php.h
PHP_METHOD
#define PHP_METHOD
Definition
php.h:365
php_mysqli_structs.h
report_mode
zend_long report_mode
Definition
php_mysqli_structs.h:254
MyG
#define MyG(v)
Definition
php_mysqli_structs.h:258
sqlstate
char sqlstate[6]
Definition
php_pdo_dblib_int.h:145
rv
zval rv
Definition
session.c:1024
signal.h
vspprintf
#define vspprintf
Definition
spprintf.h:31
object_init_ex
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition
zend_API.c:1849
zend_read_property
ZEND_API zval * zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv)
Definition
zend_API.c:5201
zend_update_property_string
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value)
Definition
zend_API.c:5066
zend_update_property_long
ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value)
Definition
zend_API.c:5039
ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE()
Definition
zend_API.h:1623
RETURN_STR
#define RETURN_STR(s)
Definition
zend_API.h:1039
ZEND_THIS
#define ZEND_THIS
Definition
zend_API.h:523
efree
#define efree(ptr)
Definition
zend_alloc.h:155
zval
struct _zval_struct zval
Definition
zend_builtin_functions.h:25
E_WARNING
#define E_WARNING
Definition
zend_errors.h:24
zend_throw_exception_object
ZEND_API ZEND_COLD void zend_throw_exception_object(zval *exception)
Definition
zend_exceptions.c:990
zend_exceptions.h
zend_string
struct _zend_string zend_string
Definition
zend_map_ptr.h:24
ZVAL_DEREF
#define ZVAL_DEREF(z)
Definition
zend_types.h:1462
Z_OBJ_P
#define Z_OBJ_P(zval_p)
Definition
zend_types.h:990
Z_OBJ
#define Z_OBJ(zval)
Definition
zend_types.h:989
ext
mysqli
mysqli_exception.c
Generated on Sat Aug 23 2025 01:46:09 for php-internal-docs by
1.13.2