I've added two functions - sybase_get_last_error and
sybase_get_last_error_no (alias functions for mssql_xxxx are included), so
that the user can do error handling with the errors raised from sybase or
mssql.
I've included a unified diff for these changes. Tested on Apache and MS
SQL. They are only minor changes, so shouldn't affect anything else.
Do I have to do anything else with the source to submit it?
If anyone wants the changes applying to the mssql extension, then let me
know - they'll be the same changes.
Corrections / comments welcome.
Thanks a lot,
Dave.
--- ext/sybase/php_sybase_db.c Thu Dec 13 08:50:45 2001
+++ ext/sybase/php_sybase_db.c Thu Dec 13 10:43:50 2001
@@ -88,6 +88,8 @@
PHP_FE(sybase_query, NULL)
PHP_FE(sybase_free_result, NULL)
PHP_FE(sybase_get_last_message, NULL)
+ PHP_FE(sybase_get_last_error, NULL)
+ PHP_FE(sybase_get_last_error_no, NULL)
PHP_FE(sybase_num_rows, NULL)
PHP_FE(sybase_num_fields, NULL)
PHP_FE(sybase_fetch_row, NULL)
@@ -107,6 +109,8 @@
PHP_FALIAS(mssql_query, sybase_query, NULL)
PHP_FALIAS(mssql_free_result, sybase_free_result, NULL)
PHP_FALIAS(mssql_get_last_message, sybase_get_last_message, NULL)
+ PHP_FALIAS(mssql_get_last_error, sybase_get_last_error, NULL)
+ PHP_FALIAS(mssql_get_last_error_no, sybase_get_last_error_no, NULL)
PHP_FALIAS(mssql_num_rows, sybase_num_rows, NULL)
PHP_FALIAS(mssql_num_fields, sybase_num_fields, NULL)
PHP_FALIAS(mssql_fetch_row, sybase_fetch_row, NULL)
@@ -146,6 +150,9 @@
if (severity >= php_sybase_module.min_error_severity) {
php_error(E_WARNING,"Sybase error: %s (severity
%d)",dberrstr,severity);
}
+ STR_FREE(php_sybase_module.error_message);
+ php_sybase_module.error_message = estrdup(dberrstr);
+ php_sybase_module.error_no = dberr;
return INT_CANCEL;
}
@@ -281,6 +288,8 @@
php_sybase_module.num_links = php_sybase_module.num_persistent;
php_sybase_module.appname = estrndup("PHP 4.0",7);
php_sybase_module.server_message = empty_string;
+ php_sybase_module.error_message = empty_string;
+ php_sybase_module.error_no = 0;
php_sybase_module.min_error_severity =
php_sybase_module.cfg_min_error_severity;
php_sybase_module.min_message_severity =
php_sybase_module.cfg_min_message_severity;
return SUCCESS;
@@ -912,6 +921,24 @@
PHP_FUNCTION(sybase_get_last_message)
{
RETURN_STRING(php_sybase_module.server_message,1);
+}
+/* }}} */
+
+/* {{{ proto string sybase_get_last_error(void)
+ Returns the last error from server (not affected by min_error_severity) */
+PHP_FUNCTION(sybase_get_last_error)
+{
+ RETURN_STRING(php_sybase_module.error_message,1);
+}
+/* }}} */
+
+/* {{{ proto int sybase_get_last_error_no(void)
+ Returns the last error number from server
+ (not affected by min_error_severity) */
+PHP_FUNCTION(sybase_get_last_error_no)
+{
+ Z_LVAL_P(return_value) = php_sybase_module.error_no;
+ Z_TYPE_P(return_value) = IS_LONG;
}
/* }}} */
--- ext/sybase/php_sybase_db.h Thu Dec 13 08:50:13 2001
+++ ext/sybase/php_sybase_db.h Thu Dec 13 10:43:50 2001
@@ -38,6 +38,8 @@
PHP_FUNCTION(sybase_query);
PHP_FUNCTION(sybase_free_result);
PHP_FUNCTION(sybase_get_last_message);
+PHP_FUNCTION(sybase_get_last_error);
+PHP_FUNCTION(sybase_get_last_error_no);
PHP_FUNCTION(sybase_num_rows);
PHP_FUNCTION(sybase_num_fields);
PHP_FUNCTION(sybase_fetch_row);
@@ -70,6 +72,8 @@
long allow_persistent;
char *appname;
char *server_message;
+ char *error_message;
+ int error_no;
int le_link,le_plink,le_result;
long min_error_severity,min_message_severity;
long cfg_min_error_severity,cfg_min_message_severity;
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]