mysqli_report.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "php_ini.h"
  21. #include "ext/standard/info.h"
  22. #include "php_mysqli_structs.h"
  23. extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);
  24. /* {{{ sets report level */
  25. PHP_FUNCTION(mysqli_report)
  26. {
  27. zend_long flags;
  28. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) {
  29. RETURN_THROWS();
  30. }
  31. MyG(report_mode) = flags;
  32. RETURN_TRUE;
  33. }
  34. /* }}} */
  35. /* {{{ void php_mysqli_report_error(char *sqlstate, int errorno, char *error) */
  36. void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error)
  37. {
  38. php_mysqli_throw_sql_exception((char *)sqlstate, errorno, "%s", error);
  39. }
  40. /* }}} */
  41. /* {{{ void php_mysqli_report_index() */
  42. void php_mysqli_report_index(const char *query, unsigned int status) {
  43. char index[15];
  44. if (status & SERVER_QUERY_NO_GOOD_INDEX_USED) {
  45. strcpy(index, "Bad index");
  46. } else if (status & SERVER_QUERY_NO_INDEX_USED) {
  47. strcpy(index, "No index");
  48. } else {
  49. return;
  50. }
  51. php_mysqli_throw_sql_exception("00000", 0, "%s used in query/prepared statement %s", index, query);
  52. }
  53. /* }}} */