diff options
| author | Jason Greene <jason@php.net> | 2001-05-04 01:14:26 +0000 | 
|---|---|---|
| committer | Jason Greene <jason@php.net> | 2001-05-04 01:14:26 +0000 | 
| commit | 8405c36815967e1e7b8812de1fc31a8c465197a3 (patch) | |
| tree | b41683648027924654e2c4a7be5e414d6722c5c3 /ext/mysql/php_mysql.c | |
| parent | 36d2e71de1a2a0dee46482a17feb18433c9ac7af (diff) | |
| download | php-git-8405c36815967e1e7b8812de1fc31a8c465197a3.tar.gz | |
@ 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.
Diffstat (limited to 'ext/mysql/php_mysql.c')
| -rw-r--r-- | ext/mysql/php_mysql.c | 29 | 
1 files changed, 26 insertions, 3 deletions
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index a22c40b91b..e79d6b8228 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -286,6 +286,8 @@ static void php_mysql_init_globals(zend_mysql_globals *mysql_globals)  	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 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)  #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 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)  #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 @@ PHP_FUNCTION(mysql_error)  		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 @@ PHP_FUNCTION(mysql_errno)  		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:  | 
