cvs: php4 /ext/mysql php_mysql.c php_mysql.h
| From: | Jason Greene | Date: | Fri, 04 May 2001 01:14:26 +0000 |
| Subject: | cvs: php4 /ext/mysql php_mysql.c php_mysql.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5515@lists.php.net to get a copy of this message | ||
jason Thu May 3 18:14:26 2001 EDT
Modified files:
/php4/ext/mysql php_mysql.c php_mysql.h
Log:
@ Added connection error support to mysql_error() and mysql_errno() (Jason)
This should work correctly without causing compatibility issues with previous
scripts. Someone might want to double check this change, just in case.
Index: php4/ext/mysql/php_mysql.c
diff -u php4/ext/mysql/php_mysql.c:1.79 php4/ext/mysql/php_mysql.c:1.80
--- php4/ext/mysql/php_mysql.c:1.79 Tue May 1 17:21:25 2001
+++ php4/ext/mysql/php_mysql.c Thu May 3 18:14:26 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.c,v 1.79 2001/05/02 00:21:25 sniper Exp $ */
+/* $Id: php_mysql.c,v 1.80 2001/05/04 01:14:26 jason Exp $ */
/* TODO:
@@ -286,6 +286,8 @@
mysql_globals->default_host = NULL;
mysql_globals->default_user = NULL;
mysql_globals->default_password = NULL;
+ mysql_globals->connect_errno = 0;
+ mysql_globals->connect_error = NULL;
}
@@ -490,7 +492,13 @@
#else
if (mysql_connect(&mysql->conn, host, user, passwd)==NULL) {
#endif
- php_error(E_WARNING, "%s", mysql_error(&mysql->conn));
+ /* Populate connect error globals so that the error functions can read them */
+ if (MySG(connect_error)!=NULL) efree(MySG(connect_error));
+ MySG(connect_error)=estrdup(mysql_error(&mysql->conn));
+ php_error(E_WARNING, "%s", MySG(connect_error));
+#if defined(HAVE_MYSQL_ERRNO)
+ MySG(connect_errno)=mysql_errno(&mysql->conn);
+#endif
free(mysql);
efree(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
@@ -577,6 +585,13 @@
#else
if (mysql_connect(&mysql->conn, host, user, passwd)==NULL) {
#endif
+ /* Populate connect error globals so that the error functions can read them */
+ if (MySG(connect_error)!=NULL) efree(MySG(connect_error));
+ MySG(connect_error)=estrdup(mysql_error(&mysql->conn));
+ php_error(E_WARNING, "%s", MySG(connect_error));
+#if defined(HAVE_MYSQL_ERRNO)
+ MySG(connect_errno)=mysql_errno(&mysql->conn);
+#endif
php_error(E_WARNING, "MySQL Connection Failed: %s\n",
mysql_error(&mysql->conn));
efree(hashed_details);
efree(mysql);
@@ -1180,7 +1195,11 @@
case 0:
id = MySG(default_link);
if (id==-1) {
- RETURN_FALSE;
+ if (MySG(connect_error)!=NULL){
+ RETURN_STRING(MySG(connect_error),1);
+ } else {
+ RETURN_FALSE;
+ }
}
break;
case 1:
@@ -1215,7 +1234,11 @@
case 0:
id = MySG(default_link);
if (id==-1) {
- RETURN_FALSE;
+ if (MySG(connect_errno)!=0){
+ RETURN_LONG(MySG(connect_errno));
+ } else {
+ RETURN_FALSE;
+ }
}
break;
case 1:
Index: php4/ext/mysql/php_mysql.h
diff -u php4/ext/mysql/php_mysql.h:1.19 php4/ext/mysql/php_mysql.h:1.20
--- php4/ext/mysql/php_mysql.h:1.19 Tue Mar 13 14:52:53 2001
+++ php4/ext/mysql/php_mysql.h Thu May 3 18:14:26 2001
@@ -17,7 +17,7 @@
*/
-/* $Id: php_mysql.h,v 1.19 2001/03/13 22:52:53 zeev Exp $ */
+/* $Id: php_mysql.h,v 1.20 2001/05/04 01:14:26 jason Exp $ */
#ifndef PHP_MYSQL_H
#define PHP_MYSQL_H
@@ -90,6 +90,8 @@
long default_port;
char *default_host, *default_user, *default_password;
char *default_socket;
+ char *connect_error;
+ long connect_errno;
ZEND_END_MODULE_GLOBALS(mysql)
#ifdef ZTS