]> granicus.if.org Git - php/commitdiff
Add methods for error handling
authorWez Furlong <wez@php.net>
Thu, 20 May 2004 17:22:13 +0000 (17:22 +0000)
committerWez Furlong <wez@php.net>
Thu, 20 May 2004 17:22:13 +0000 (17:22 +0000)
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c

index d54e9fef0d6be2d4171faccbcdd33739f00b8953..37729d5c65ee8f06ec640471dde9e49d66778af5 100755 (executable)
@@ -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}
 };
index 494570fcabf981241fad996de4a18889414b7ee1..dce37366958b46637f080d159bc130bf971338c4 100755 (executable)
@@ -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}
 };