xref: /PHP-7.4/ext/mysqli/mysqli_report.c (revision 92ac598a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 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 "php.h"
24 #include "php_ini.h"
25 #include "ext/standard/info.h"
26 #include "php_mysqli_structs.h"
27 
28 extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);
29 
30 /* {{{ proto bool mysqli_report(int flags)
31    sets report level */
PHP_FUNCTION(mysqli_report)32 PHP_FUNCTION(mysqli_report)
33 {
34 	zend_long flags;
35 
36 
37 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) {
38 		return;
39 	}
40 
41 	MyG(report_mode) = flags;
42 
43 	RETURN_TRUE;
44 }
45 /* }}} */
46 
47 /* {{{ void php_mysqli_report_error(char *sqlstate, int errorno, char *error) */
php_mysqli_report_error(const char * sqlstate,int errorno,const char * error)48 void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error)
49 {
50 	php_mysqli_throw_sql_exception((char *)sqlstate, errorno, "%s", error);
51 }
52 /* }}} */
53 
54 /* {{{ void php_mysqli_report_index() */
php_mysqli_report_index(const char * query,unsigned int status)55 void php_mysqli_report_index(const char *query, unsigned int status) {
56 	char index[15];
57 
58 	if (status & SERVER_QUERY_NO_GOOD_INDEX_USED) {
59 		strcpy(index, "Bad index");
60 	} else if (status & SERVER_QUERY_NO_INDEX_USED) {
61 		strcpy(index, "No index");
62 	} else {
63 		return;
64 	}
65 	php_mysqli_throw_sql_exception("00000", 0, "%s used in query/prepared statement %s", index, query);
66 }
67 /* }}} */
68