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
28void 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
39 php_error_docref(NULL, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
40 efree(message);
41 return;
42 }
43
45
46 if (message) {
48 mysqli_exception_class_entry, Z_OBJ(sql_ex), "message", sizeof("message") - 1, message);
49 }
50
51 if (sqlstate) {
53 mysqli_exception_class_entry, Z_OBJ(sql_ex), "sqlstate", sizeof("sqlstate") - 1, sqlstate);
54 } else {
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
63}
64
66{
67 zval *prop;
68 zval rv;
69
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}
zval * arg
Definition ffi.c:3975
#define NULL
Definition gdcache.h:45
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
zend_class_entry * mysqli_exception_class_entry
Definition mysqli.c:71
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format,...)
#define MYSQLI_REPORT_STRICT
#define PHP_METHOD
Definition php.h:365
zend_long report_mode
#define MyG(v)
char sqlstate[6]
zval rv
Definition session.c:1024
#define vspprintf
Definition spprintf.h:31
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
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_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_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
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define RETURN_STR(s)
Definition zend_API.h:1039
#define ZEND_THIS
Definition zend_API.h:523
#define efree(ptr)
Definition zend_alloc.h:155
struct _zval_struct zval
#define E_WARNING
Definition zend_errors.h:24
ZEND_API ZEND_COLD void zend_throw_exception_object(zval *exception)
struct _zend_string zend_string
#define ZVAL_DEREF(z)
#define Z_OBJ_P(zval_p)
Definition zend_types.h:990
#define Z_OBJ(zval)
Definition zend_types.h:989