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