Justtechjobs.com Find a programming school near you






Online Campus Both


php-developer-list | 2000111

Re: [PHP-DEV] (Updated) Patch to add odbc_errno(), odbc_error(), odbc_clear_error() From: Lars Torben Wilson (torben <email protected>)
Date: 11/05/00

Lars Torben Wilson writes:
> > What about errors (connecting to a datasource) where you don't have a
> > connection handle?
>
> I had originally thought about maintaining a global hash of the error
> states & strings instead of having them part of the connection
> handle--but that got into a whole bunch of thread-safety weirdness
> and just seemed like a lot of code to do a simple thing.
>
> One idea would be that if i.e. odbc_errno() is called without a $dbh,
> it would directly use SQLError() to find the last error to have
> occurred at all.

Of course, that's a braindead idea since you'd need a connection
handle to do that. :)

I'd also wanted to do it like mysql_errno(): if no handle is passed,
then the default handle is used--which is consistent with the way most
(all?) mysql_*() functions which take a connection handle work. I
found an ODBCG global called defConn, which looked promising, but it
never seems to get used--I'm not sure, but it looks like odbc_*()
doesn't support default link ids like mysql_*().

So what I've done now is simply copy every error state & message into
a pair of strings in ODBCG. Now, when odbc_error(), odbc_errno(), or
odbc_clear_error() are called without a link id, they will fetch/clear
ODBCG(last_state) or ODBCG(last_errormsg), as appropriate.
 
> > > It also shuts up the php_error(E_WARNING, ...) from within
> > > odbc_sql_error(), but that's not really necessary...

I've removed the #if PHP_DEBUG from this again...it seems reasonable
that a PHP warning be issued, since the other db functions do it when
something goes wrong.

Does this come closer to addressing what you (Andreas) meant? Thanks
again for any comments...

Anyway, here's the new diff (against cvs, not against what I sent
earlier):

Index: php_odbc.c
===================================================================
RCS file: /repository/php4/ext/odbc/php_odbc.c,v
retrieving revision 1.63
diff -u -r1.63 php_odbc.c
--- php_odbc.c 2000/10/25 17:43:58 1.63
+++ php_odbc.c 2000/11/06 00:11:50
@@ -113,6 +113,9 @@
         PHP_FE(odbc_statistics, NULL)
         PHP_FALIAS(odbc_do, odbc_exec, NULL)
         PHP_FALIAS(odbc_field_precision, odbc_field_len, NULL)
+ PHP_FE(odbc_error, NULL)
+ PHP_FE(odbc_errno, NULL)
+ PHP_FE(odbc_clear_error, NULL)
         { NULL, NULL, NULL }
 };
 
@@ -312,6 +315,7 @@
 static void php_odbc_init_globals(php_odbc_globals *odbc_globals)
 {
         ODBCG(num_persistent) = 0;
+ odbc_clear_error(ODBCG(last_state), ODBCG(last_errormsg);
 }
 #endif
 
@@ -458,6 +462,13 @@
 
 }
 
+void odbc_clear_error(char *state, char *message)
+{
+ strncpy(state, "00000", PHP_ODBC_STATE_LENGTH);
+ state[PHP_ODBC_STATE_LENGTH] = '\0';
+ message[0] = '\0';
+}
+
 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS)
 {
         char state[6];
@@ -474,7 +485,11 @@
          */
                         rc = SQLError(henv, conn, stmt, state,
                             &error, errormsg, sizeof(errormsg)-1, &errormsgsize);
- if (func) {
+ snprintf(rconn->state, PHP_ODBC_STATE_LENGTH, "%s", state);
+ snprintf(rconn->errormsg, PHP_ODBC_MAX_ERROR_LENGTH, "%s", errormsg);
+ strcpy(ODBCG(last_state), rconn->state);
+ strcpy(ODBCG(last_errormsg), rconn->errormsg);
+ if (func) {
                             php_error(E_WARNING, "SQL error: %s, SQL state %s in %s",
                                    errormsg, state, func);
                         } else {
@@ -590,7 +605,7 @@
         
         rc = SQLTransact(conn->henv, conn->hdbc, (UWORD)((type)?SQL_COMMIT:SQL_ROLLBACK));
         if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTransact");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTransact");
                 RETURN_FALSE;
         }
 
@@ -655,6 +670,93 @@
 
 /* Main User Functions */
 
+/* {{{ proto string odbc_errno([int link_identifier])
+ Returns the last ODBC error state string for the given link id. If no link id is given, returns the last recorded ODBC error state. */
+PHP_FUNCTION(odbc_errno)
+{
+ odbc_connection *conn;
+ pval **pv_conn;
+ ODBCLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 0:
+ RETURN_STRING(ODBCG(last_state), 1);
+ break;
+ case 1:
+ if (zend_get_parameters_ex(1, &pv_conn) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn);
+
+ RETURN_STRING(conn->state, 1);
+}
+/* }}} */
+
+
+/* {{{ proto string odbc_error(int link_identifier)
+ Returns the textual description of the last ODBC error state string for the given link id. If no link id is given, returns the last recorded ODBC error message. */
+PHP_FUNCTION(odbc_error)
+{
+ odbc_connection *conn;
+ pval **pv_conn;
+ ODBCLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 0:
+ RETURN_STRING(ODBCG(last_errormsg), 1);
+ break;
+ case 1:
+ if (zend_get_parameters_ex(1, &pv_conn) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn);
+
+ RETURN_STRING(conn->errormsg, 1);
+}
+/* }}} */
+
+/* {{{ proto int odbc_clear_error(int link_identifier)
+ Resest the link id's error state to "00000" and error string to empty. If no link id is given, clears the record of the last ODBC error. */
+PHP_FUNCTION(odbc_clear_error)
+{
+ odbc_connection *conn;
+ pval **pv_conn;
+ ODBCLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 0:
+ odbc_clear_error(ODBCG(last_state), ODBCG(last_errormsg));
+ RETURN_TRUE;
+ break;
+ case 1:
+ if (zend_get_parameters_ex(1, &pv_conn) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn);
+
+ odbc_clear_error(conn->state, conn->errormsg);
+ RETURN_TRUE;
+}
+/* }}} */
+
 /* {{{ proto void odbc_close_all(void)
    Close all ODBC connections */
 PHP_FUNCTION(odbc_close_all)
@@ -747,7 +849,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -763,7 +865,7 @@
                         */
                         if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC)
                                 == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
                                 SQLFreeStmt(result->stmt, SQL_DROP);
                                 efree(result);
                                 RETURN_FALSE;
@@ -775,7 +877,7 @@
 #endif
 
         if ((rc = SQLPrepare(result->stmt, query, SQL_NTS)) != SQL_SUCCESS) {
- odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLPrepare");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, result->stmt, "SQLPrepare");
                 SQLFreeStmt(result->stmt, SQL_DROP);
                 RETURN_FALSE;
         }
@@ -916,7 +1018,7 @@
         rc = SQLFreeStmt(result->stmt, SQL_CLOSE);
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLFreeStmt");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLFreeStmt");
         }
 
         rc = SQLExecute(result->stmt);
@@ -934,7 +1036,7 @@
                 }
         } else {
                 if (rc != SQL_SUCCESS) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLExecute");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLExecute");
                         RETVAL_FALSE;
                 }
         }
@@ -1010,7 +1112,7 @@
                         if (!strncmp(state,"S1015",5)) {
                                 sprintf(cursorname,"php_curs_%d", (int)result->stmt);
                                 if (SQLSetCursorName(result->stmt,cursorname,SQL_NTS) != SQL_SUCCESS) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc,
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc,
                                                                         result->stmt, "SQLSetCursorName");
                                         RETVAL_FALSE;
                                 } else {
@@ -1074,7 +1176,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -1090,7 +1192,7 @@
                          */
                         if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC)
                                 == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
                                 SQLFreeStmt(result->stmt, SQL_DROP);
                                 efree(result);
                                 RETURN_FALSE;
@@ -1106,7 +1208,7 @@
                 /* XXX FIXME we should really check out SQLSTATE with SQLError
                  * in case rc is SQL_SUCCESS_WITH_INFO here.
                  */
- odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLExecDirect");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, result->stmt, "SQLExecDirect");
                 SQLFreeStmt(result->stmt, SQL_DROP);
                 efree(result);
                 RETURN_FALSE;
@@ -1231,7 +1333,7 @@
         buf, result->longreadlen + 1, &result->values[i].vallen);
 
      if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
      efree(buf);
      RETURN_FALSE;
     }
@@ -1396,7 +1498,7 @@
                                                                 buf, result->longreadlen + 1, &result->values[i].vallen);
 
                                         if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
                                         efree(buf);
                                         RETURN_FALSE;
                                 }
@@ -1616,7 +1718,7 @@
                             field, fieldsize, &result->values[field_ind].vallen);
             
             if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
                 efree(field);
                 RETURN_FALSE;
             }
@@ -1659,7 +1761,7 @@
                             field, fieldsize, &result->values[field_ind].vallen);
 
                 if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
             efree(field);
                         RETURN_FALSE;
                 }
@@ -1765,7 +1867,7 @@
                                         php_printf("<td>");
 
                                         if (rc == SQL_ERROR) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
                                                 php_printf("</td></tr></table>");
                                                 efree(buf);
                                                 RETURN_FALSE;
@@ -1864,7 +1966,7 @@
         if (cur_opt != SQL_CUR_DEFAULT) {
                 rc = SQLSetConnectOption((*conn)->hdbc, SQL_ODBC_CURSORS, cur_opt);
                 if (rc != SQL_SUCCESS) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
- odbc_sql_error((*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLSetConnectOption");
+ odbc_sql_error((*conn), (*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLSetConnectOption");
                         SQLFreeConnect((*conn)->hdbc);
                         pefree(*conn, persistent);
                         return FALSE;
@@ -1902,12 +2004,13 @@
 #endif
 #endif
         if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error((*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLConnect");
+ odbc_sql_error((*conn), (*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLConnect");
                 SQLFreeConnect((*conn)->hdbc);
                 pefree((*conn), persistent);
                 return FALSE;
         }
 /* (*conn)->open = 1;*/
+ odbc_clear_error((*conn)->state, (*conn)->errormsg);
         return TRUE;
 }
 /* Persistent connections: two list-types le_pconn, le_conn and a plist
@@ -2345,7 +2448,7 @@
                                                                  ((*pv_onoff)->value.lval) ?
                                                                  SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF);
                 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Set autocommit");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Set autocommit");
                         RETURN_FALSE;
                 }
                 RETVAL_TRUE;
@@ -2354,7 +2457,7 @@
 
                 rc = SQLGetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, (PTR)&status);
                 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Get commit status");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Get commit status");
                         RETURN_FALSE;
                 }
                 RETVAL_LONG((long)status);
@@ -2411,7 +2514,7 @@
                         }
                         rc = SQLSetConnectOption(conn->hdbc, (unsigned short)((*pv_opt)->value.lval), (*pv_val)->value.lval);
                         if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SetConnectOption");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SetConnectOption");
                                 RETURN_FALSE;
                         }
                         break;
@@ -2421,7 +2524,7 @@
                         rc = SQLSetStmtOption(result->stmt, (unsigned short)((*pv_opt)->value.lval), ((*pv_val)->value.lval));
 
                         if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SetStmtOption");
+ odbc_sql_error(result->conn_ptr, result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SetStmtOption");
                                 RETURN_FALSE;
                         }
                         break;
@@ -2485,7 +2588,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2497,7 +2600,7 @@
             type, SAFE_SQL_NTS(type));
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTables");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTables");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2565,7 +2668,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2577,7 +2680,7 @@
             column, SAFE_SQL_NTS(column));
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumns");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumns");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2644,7 +2747,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2656,7 +2759,7 @@
             column, SAFE_SQL_NTS(column));
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumnPrivileges");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumnPrivileges");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2742,7 +2845,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2756,7 +2859,7 @@
             ftable, SAFE_SQL_NTS(ftable) );
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLForeignKeys");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLForeignKeys");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2821,7 +2924,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2829,7 +2932,7 @@
         rc = SQLGetTypeInfo(result->stmt, data_type );
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLGetTypeInfo");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLGetTypeInfo");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2893,7 +2996,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2904,7 +3007,7 @@
             table, SAFE_SQL_NTS(table) );
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLPrimaryKeys");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLPrimaryKeys");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2975,7 +3078,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -2987,7 +3090,7 @@
             col, SAFE_SQL_NTS(col) );
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedureColumns");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedureColumns");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3057,7 +3160,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3068,7 +3171,7 @@
             proc, SAFE_SQL_NTS(proc) );
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedures");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedures");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3143,7 +3246,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3157,7 +3260,7 @@
             nullable);
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLSpecialColumns");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLSpecialColumns");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3228,7 +3331,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3241,7 +3344,7 @@
             reserved);
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLStatistics");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLStatistics");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3306,7 +3409,7 @@
         }
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
                 efree(result);
                 RETURN_FALSE;
         }
@@ -3317,7 +3420,7 @@
             table, SAFE_SQL_NTS(table));
 
         if (rc == SQL_ERROR) {
- odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTablePrivileges");
+ odbc_sql_error(conn, conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTablePrivileges");
                 efree(result);
                 RETURN_FALSE;
         }
Index: php_odbc.h
===================================================================
RCS file: /repository/php4/ext/odbc/php_odbc.h,v
retrieving revision 1.29
diff -u -r1.29 php_odbc.h
--- php_odbc.h 2000/10/30 18:00:58 1.29
+++ php_odbc.h 2000/11/06 00:11:51
@@ -225,7 +225,13 @@
 PHP_FUNCTION(odbc_primarykeys);
 PHP_FUNCTION(odbc_specialcolumns);
 PHP_FUNCTION(odbc_statistics);
+PHP_FUNCTION(odbc_error);
+PHP_FUNCTION(odbc_errno);
+PHP_FUNCTION(odbc_clear_error);
 
+#define PHP_ODBC_STATE_LENGTH 6
+#define PHP_ODBC_MAX_ERROR_LENGTH SQL_MAX_MESSAGE_LENGTH
+
 typedef struct odbc_connection {
 #if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC )
         SQLHANDLE henv;
@@ -239,6 +245,8 @@
 #endif
         int id;
         int persistent;
+ char state[PHP_ODBC_STATE_LENGTH];
+ char errormsg[PHP_ODBC_MAX_ERROR_LENGTH];
 } odbc_connection;
 
 typedef struct odbc_result_value {
@@ -284,6 +292,8 @@
     long defaultbinmode;
         HashTable *resource_list;
         HashTable *resource_plist;
+ char last_state[PHP_ODBC_STATE_LENGTH];
+ char last_errormsg[PHP_ODBC_MAX_ERROR_LENGTH];
 } php_odbc_globals;
 
 int odbc_add_result(HashTable *list, odbc_result *result);
@@ -295,11 +305,11 @@
 int odbc_bindcols(odbc_result *result);
 
 #if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC )
-#define ODBC_SQL_ERROR_PARAMS SQLHANDLE henv, SQLHANDLE conn, SQLHANDLE stmt, char *func
+#define ODBC_SQL_ERROR_PARAMS odbc_connection *rconn, SQLHANDLE henv, SQLHANDLE conn, SQLHANDLE stmt, char *func
 #elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB )
-#define ODBC_SQL_ERROR_PARAMS SQLHENV henv, SQLHDBC conn, SQLHSTMT stmt, char *func
+#define ODBC_SQL_ERROR_PARAMS odbc_connection *rconn, SQLHENV henv, SQLHDBC conn, SQLHSTMT stmt, char *func
 #else
-#define ODBC_SQL_ERROR_PARAMS HENV henv, HDBC conn, HSTMT stmt, char *func
+#define ODBC_SQL_ERROR_PARAMS odbc_connection *rconn, HENV henv, HDBC conn, HSTMT stmt, char *func
 #endif
 
 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);

-- 
+----------------------------------------------------------------+
|Torben Wilson <torben <email protected>>                     Netmill iTech|
|http://www.coastnet.com/~torben            http://www.netmill.fi|
|Ph: 1 250 383-9735                             torben <email protected>|
+----------------------------------------------------------------+

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>