[PHP-DEV] Bug #3065: Solution to '...undefined function mysql_errno()' From: pcg <email protected>
Date: 12/29/99

From: pcg <email protected>
Operating system: Linux (RH6.0, kernel 2.2.13)
PHP version: 3.0.12
PHP Bug Type: MySQL related
Bug description: Solution to '...undefined function mysql_errno()'

As with bug #2329, I'm getting 'Fatal error: Call to unsupported or undefined function mysql_errno()...' from a script.

The problem is that with MySQL-3.23 mysql_errno is NOT #define'd, as it was with 3.22--it is a true function. Thus, in lines 118-120 of functions/mysql.c, where mysql_errno is tested to be defined or not, php3_mysql_errno doesn't get declared.

The following patch tests if mysql_errno is defined OR if the MySQL version is 3.23. If either is true, it defines a variable (HAVE_MYSQL_ERRNO). The rest of functions/mysql.c tests if this variable is defined, rather than testing if mysql_errno is defined.

Though this patch is untested, it compiled fine and the proper symbols resulted in libmodphp3.a. Compilation was done with egcs 2.91.66, apache_1.3.9, php-3.0.12, and both mysql-3.22.25 and 3.23.7. (Undoubtedly there will be problems with linewrapping; please e-mail me if you want the raw text.)

--- cut here ---
diff -ru php-3.0.12-orig/functions/mysql.c php-3.0.12/functions/mysql.c
--- php-3.0.12-orig/functions/mysql.c Sun Jul 4 13:30:42 1999
+++ php-3.0.12/functions/mysql.c Wed Dec 29 10:57:15 1999
@@ -98,6 +98,10 @@
 #define mysql_row_length_type unsigned int
 #endif

+#if defined(mysql_errno) || MYSQL_VERSION_ID > 32299
+#define HAVE_MYSQL_ERRNO 1
+#endif
+
 #define MYSQL_ASSOC 1<<0
 #define MYSQL_NUM 1<<1
 #define MYSQL_BOTH (MYSQL_ASSOC|MYSQL_NUM)
@@ -115,7 +119,7 @@
        {"mysql_list_tables", php3_mysql_list_tables, NULL},
        {"mysql_list_fields", php3_mysql_list_fields, NULL},
        {"mysql_error", php3_mysql_error,
NULL},
-#ifdef mysql_errno
+#ifdef HAVE_MYSQL_ERRNO
        {"mysql_errno", php3_mysql_errno,
NULL},
 #endif
        {"mysql_affected_rows", php3_mysql_affected_rows, NULL},
@@ -529,7 +533,7 @@
 #if APACHE
                        handler=signal(SIGPIPE,SIG_IGN);
 #endif
-#if defined(mysql_errno) && defined(CR_SERVER_GONE_ERROR)
+#if defined(HAVE_MYSQL_ERRNO) && defined(CR_SERVER_GONE_ERROR)
                        mysql_stat(le->ptr);
                        if (mysql_errno((MYSQL *)le->ptr) == CR_SERVER_GONE_ERROR) {
 #else
@@ -1144,7 +1148,7 @@

 /* {{{ proto int mysql_errno([int link_identifier])
    Returns the number of the error message from previous MySQL operation */
-#ifdef mysql_errno
+#ifdef HAVE_MYSQL_ERRNO
 void php3_mysql_errno(INTERNAL_FUNCTION_PARAMETERS)
 {
        pval *mysql_link;

-- 
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>