1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2014 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 {NULL, NULL, NULL}
36 };
37 /* }}} */
38
php_mysqli_throw_sql_exception(char * sqlstate,int errorno TSRMLS_DC,char * format,...)39 void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, 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 TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
51 efree(message);
52 return;
53 }
54
55 MAKE_STD_ZVAL(sql_ex);
56 object_init_ex(sql_ex, mysqli_exception_class_entry);
57
58 if (message) {
59 zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1,
60 message TSRMLS_CC);
61 }
62
63 if (sqlstate) {
64 zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
65 sqlstate TSRMLS_CC);
66 } else {
67 zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
68 "00000" TSRMLS_CC);
69 }
70
71 efree(message);
72 zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);
73
74 zend_throw_exception_object(sql_ex TSRMLS_CC);
75 }
76
77 /*
78 * Local variables:
79 * tab-width: 4
80 * c-basic-offset: 4
81 * indent-tabs-mode: t
82 * End:
83 * vim600: noet sw=4 ts=4 fdm=marker
84 * vim<600: noet sw=4 ts=4
85 */
86