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