mysqli_exception.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <signal.h>
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "ext/standard/info.h"
  25. #include "php_mysqli_structs.h"
  26. #include "mysqli_priv.h"
  27. #include "zend_exceptions.h"
  28. /* {{{ mysqli_exception_methods[]
  29. */
  30. const zend_function_entry mysqli_exception_methods[] = {
  31. PHP_FE_END
  32. };
  33. /* }}} */
  34. void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...)
  35. {
  36. zval sql_ex;
  37. va_list arg;
  38. char *message;
  39. va_start(arg, format);
  40. vspprintf(&message, 0, format, arg);
  41. va_end(arg);
  42. if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
  43. php_error_docref(NULL, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
  44. efree(message);
  45. return;
  46. }
  47. object_init_ex(&sql_ex, mysqli_exception_class_entry);
  48. if (message) {
  49. zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "message", sizeof("message") - 1,
  50. message);
  51. }
  52. if (sqlstate) {
  53. zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
  54. sqlstate);
  55. } else {
  56. zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
  57. "00000");
  58. }
  59. efree(message);
  60. zend_update_property_long(mysqli_exception_class_entry, &sql_ex, "code", sizeof("code") - 1, errorno);
  61. zend_throw_exception_object(&sql_ex);
  62. }
  63. /*
  64. * Local variables:
  65. * tab-width: 4
  66. * c-basic-offset: 4
  67. * indent-tabs-mode: t
  68. * End:
  69. * vim600: noet sw=4 ts=4 fdm=marker
  70. * vim<600: noet sw=4 ts=4
  71. */