Back to index

php5  5.3.10
mysqli_exception.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Georg Richter <georg@php.net>                                |
00016   +----------------------------------------------------------------------+
00017 
00018 */
00019 #ifdef HAVE_CONFIG_H
00020 #include "config.h"
00021 #endif
00022 
00023 #include <signal.h>
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "php_mysqli_structs.h"
00029 #include "mysqli_priv.h"
00030 #include "zend_exceptions.h"
00031 
00032 /* {{{ mysqli_exception_methods[]
00033  */
00034 const zend_function_entry mysqli_exception_methods[] = {
00035        {NULL, NULL, NULL}
00036 };
00037 /* }}} */
00038 
00039 void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...)
00040 {
00041        zval   *sql_ex;
00042        va_list arg;
00043        char   *message;
00044 
00045        va_start(arg, format);
00046        vspprintf(&message, 0, format, arg);
00047        va_end(arg);;
00048 
00049        if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
00050               php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
00051               efree(message);
00052               return;
00053        }
00054 
00055        MAKE_STD_ZVAL(sql_ex);
00056        object_init_ex(sql_ex, mysqli_exception_class_entry);
00057 
00058        if (message) {
00059               zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1,
00060                                                                message TSRMLS_CC);
00061        }
00062 
00063        if (sqlstate) {
00064               zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
00065                                                                sqlstate TSRMLS_CC);
00066        } else {
00067               zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
00068                                                                "00000" TSRMLS_CC);
00069        }
00070 
00071        efree(message);
00072        zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);
00073 
00074        zend_throw_exception_object(sql_ex TSRMLS_CC);
00075 }
00076 
00077 /*
00078  * Local variables:
00079  * tab-width: 4
00080  * c-basic-offset: 4
00081  * indent-tabs-mode: t
00082  * End:
00083  * vim600: noet sw=4 ts=4 fdm=marker
00084  * vim<600: noet sw=4 ts=4
00085  */