From: Wez Furlong Date: Thu, 20 May 2004 17:22:13 +0000 (+0000) Subject: Add methods for error handling X-Git-Tag: RELEASE_0_1~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04ccc0134d933931431e298c80c6aa699065fad9;p=php Add methods for error handling --- diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index d54e9fef0d..37729d5c65 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -370,6 +370,40 @@ static PHP_METHOD(PDO, lastInsertId) } /* }}} */ +/* {{{ proto int PDO::errorCode() + Fetch the error code associated with the last operation on the database handle */ +static PHP_METHOD(PDO, errorCode) +{ + pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + RETURN_LONG(dbh->error_code); +} +/* }}} */ + +/* {{{ proto int PDO::errorInfo() + Fetch extended error information associated with the last operation on the database handle */ +static PHP_METHOD(PDO, errorInfo) +{ + pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + array_init(return_value); + add_next_index_long(return_value, dbh->error_code); + + if (dbh->methods->fetch_err) { + dbh->methods->fetch_err(dbh, NULL, return_value TSRMLS_CC); + } +} +/* }}} */ + + function_entry pdo_dbh_functions[] = { PHP_ME(PDO, prepare, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, beginTransaction,NULL, ZEND_ACC_PUBLIC) @@ -378,6 +412,8 @@ function_entry pdo_dbh_functions[] = { PHP_ME(PDO, setAttribute, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, exec, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, lastInsertId, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDO, errorCode, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDO, errorInfo, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 494570fcab..dce3736695 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -566,6 +566,39 @@ static PHP_METHOD(PDOStatement, rowCount) } /* }}} */ +/* {{{ proto int PDOStatement::errorCode() + Fetch the error code associated with the last operation on the statement handle */ +static PHP_METHOD(PDOStatement, errorCode) +{ + pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + RETURN_LONG(stmt->error_code); +} +/* }}} */ + +/* {{{ proto int PDOStatement::errorInfo() + Fetch extended error information associated with the last operation on the statement handle */ +static PHP_METHOD(PDOStatement, errorInfo) +{ + pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + array_init(return_value); + add_next_index_long(return_value, stmt->error_code); + + if (stmt->dbh->methods->fetch_err) { + stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value TSRMLS_CC); + } +} +/* }}} */ + function_entry pdo_dbstmt_functions[] = { @@ -576,6 +609,8 @@ function_entry pdo_dbstmt_functions[] = { PHP_ME(PDOStatement, rowCount, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDOStatement, fetchSingle, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDOStatement, fetchAll, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDOStatement, errorCode, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PDOStatement, errorInfo, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} };