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: Georg Richter <georg@php.net> |
16 +----------------------------------------------------------------------+
17
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <signal.h>
24
25 #include "php.h"
26 #include "php_ini.h"
27 #include "ext/standard/info.h"
28 #include "php_mysqli_structs.h"
29 #include "mysqli_priv.h"
30 #include "zend_exceptions.h"
31
32 /* {{{ mysqli_exception_methods[]
33 */
34 const zend_function_entry mysqli_exception_methods[] = {
35 PHP_FE_END
36 };
37 /* }}} */
38
php_mysqli_throw_sql_exception(char * sqlstate,int errorno,char * format,...)39 void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...)
40 {
41 zval sql_ex;
42 va_list arg;
43 char *message;
44
45 va_start(arg, format);
46 vspprintf(&message, 0, format, arg);
47 va_end(arg);
48
49 if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
50 php_error_docref(NULL, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
51 efree(message);
52 return;
53 }
54
55 object_init_ex(&sql_ex, mysqli_exception_class_entry);
56
57 if (message) {
58 zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "message", sizeof("message") - 1,
59 message);
60 }
61
62 if (sqlstate) {
63 zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
64 sqlstate);
65 } else {
66 zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
67 "00000");
68 }
69
70 efree(message);
71 zend_update_property_long(mysqli_exception_class_entry, &sql_ex, "code", sizeof("code") - 1, errorno);
72
73 zend_throw_exception_object(&sql_ex);
74 }
75
76 /*
77 * Local variables:
78 * tab-width: 4
79 * c-basic-offset: 4
80 * indent-tabs-mode: t
81 * End:
82 * vim600: noet sw=4 ts=4 fdm=marker
83 * vim<600: noet sw=4 ts=4
84 */
85