|
36 | 36 |
|
37 | 37 | static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value); |
38 | 38 |
|
| 39 | +void pdo_throw_exception(unsigned int driver_errcode, char *driver_errmsg, pdo_error_type *pdo_error) |
| 40 | +{ |
| 41 | + zval error_info,pdo_exception; |
| 42 | + char *pdo_exception_message; |
| 43 | + |
| 44 | + object_init_ex(&pdo_exception, php_pdo_get_exception()); |
| 45 | + array_init(&error_info); |
| 46 | + |
| 47 | + add_next_index_string(&error_info, *pdo_error); |
| 48 | + add_next_index_long(&error_info, driver_errcode); |
| 49 | + add_next_index_string(&error_info, driver_errmsg); |
| 50 | + |
| 51 | + spprintf(&pdo_exception_message, 0,"SQLSTATE[%s] [%d] %s",*pdo_error, driver_errcode, driver_errmsg); |
| 52 | + zend_update_property(php_pdo_get_exception(), &pdo_exception, "errorInfo", sizeof("errorInfo")-1, &error_info); |
| 53 | + zend_update_property_long(php_pdo_get_exception(), &pdo_exception, "code", sizeof("code")-1, driver_errcode); |
| 54 | + zend_update_property_string( |
| 55 | + php_pdo_get_exception(), |
| 56 | + &pdo_exception, |
| 57 | + "message", |
| 58 | + sizeof("message")-1, |
| 59 | + pdo_exception_message |
| 60 | + ); |
| 61 | + efree(pdo_exception_message); |
| 62 | + zval_ptr_dtor(&error_info); |
| 63 | + zend_throw_exception_object(&pdo_exception); |
| 64 | +} |
| 65 | + |
39 | 66 | void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *supp) /* {{{ */ |
40 | 67 | { |
41 | 68 | pdo_error_type *pdo_err = &dbh->error_code; |
|
0 commit comments