diff options
| author | Hartmut Holzgraefe <hholzgra@php.net> | 2005-02-27 20:34:36 +0000 |
|---|---|---|
| committer | Hartmut Holzgraefe <hholzgra@php.net> | 2005-02-27 20:34:36 +0000 |
| commit | f7e8fcb8e0b3a2110c31e05c4cc2a55ddaf584f6 (patch) | |
| tree | fad218e1287ccb9886357f6a76cf1d6b8dc92447 /ext/pdo_mysql/mysql_driver.c | |
| parent | 86994c3357605008a1973c1681009a5770a656e7 (diff) | |
| download | php-git-f7e8fcb8e0b3a2110c31e05c4cc2a55ddaf584f6.tar.gz | |
fully distinguish between database and statement level errors
Diffstat (limited to 'ext/pdo_mysql/mysql_driver.c')
| -rwxr-xr-x | ext/pdo_mysql/mysql_driver.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index eb8798449f..4e1ab8a822 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -44,10 +44,19 @@ const char *pdo_mysql_get_sqlstate(unsigned int my_errno) { int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC) /* {{{ */ { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; - pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code; - pdo_mysql_error_info *einfo = &H->einfo; + pdo_error_type *pdo_err; + pdo_mysql_error_info *einfo; char *sqlstate = NULL; + if (stmt) { + pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; + pdo_err = &stmt->error_code; + einfo = &S->einfo; + } else { + pdo_err = &dbh->error_code; + einfo = &H->einfo; + } + einfo->errcode = mysql_errno(H->server); einfo->file = file; einfo->line = line; @@ -64,13 +73,13 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin return 0; } + strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode)); + if (!dbh->methods) { zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } - strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode)); - return einfo->errcode; } /* }}} */ @@ -80,6 +89,13 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_error_info *einfo = &H->einfo; + if (stmt) { + pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; + einfo = &S->einfo; + } else { + einfo = &H->einfo; + } + if (einfo->errcode) { add_next_index_long(info, einfo->errcode); add_next_index_string(info, einfo->errmsg, 1); |
