CVS update: php3/functions
| From: | shane | Date: | Thu, 24 Sep 1998 19:48:19 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1468@lists.php.net to get a copy of this message | ||
Date: Thursday September 24, 1998 @ 15:48
Author: shane
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv21964/functions
Modified Files:
mysql.c
Log Message:
fix leak in request_info on windows using apache cgi.
add support for mysql_real_connect and binary safe mysql_real_query for mysql v3.22+
Index: php3/functions/mysql.c
diff -c php3/functions/mysql.c:1.165 php3/functions/mysql.c:1.166
*** php3/functions/mysql.c:1.165 Thu Sep 10 19:57:19 1998
--- php3/functions/mysql.c Thu Sep 24 15:48:18 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: mysql.c,v 1.165 1998/09/10 23:57:19 zeev Exp $ */
/* TODO:
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: mysql.c,v 1.166 1998/09/24 19:48:18 shane Exp $ */
/* TODO:
***************
*** 168,173 ****
--- 168,181 ----
#define CHECK_LINK(link) { if (link==-1) { php3_error(E_WARNING,"MySQL: A link to the server
could not be established"); RETURN_FALSE; } }
+ /* NOTE Don't ask me why, but soon as I made this the list
+ * destructor, I stoped getting access violations in windows
+ * with mysql 3.22.7a
+ */
+ static void _free_mysql_result(MYSQL_RES *mysql_result){
+ mysql_free_result(mysql_result);
+ }
+
static void _close_mysql_link(MYSQL *link)
{
#if APACHE
***************
*** 267,273 ****
#endif
}
MySQL_GLOBAL(php3_mysql_module).num_persistent=0;
! MySQL_GLOBAL(php3_mysql_module).le_result = register_list_destructors(mysql_free_result,NULL);
MySQL_GLOBAL(php3_mysql_module).le_link = register_list_destructors(_close_mysql_link,NULL);
MySQL_GLOBAL(php3_mysql_module).le_plink = register_list_destructors(NULL,_close_mysql_plink);
--- 275,281 ----
#endif
}
MySQL_GLOBAL(php3_mysql_module).num_persistent=0;
! MySQL_GLOBAL(php3_mysql_module).le_result = register_list_destructors(_free_mysql_result,NULL);
MySQL_GLOBAL(php3_mysql_module).le_link = register_list_destructors(_close_mysql_link,NULL);
MySQL_GLOBAL(php3_mysql_module).le_plink = register_list_destructors(NULL,_close_mysql_plink);
***************
*** 355,361 ****
#endif
char *user,*passwd,*host,*tmp;
char *hashed_details;
! int hashed_details_length;
MYSQL *mysql;
MySQL_TLS_VARS;
--- 363,369 ----
#endif
char *user,*passwd,*host,*tmp;
char *hashed_details;
! int hashed_details_length,port;
MYSQL *mysql;
MySQL_TLS_VARS;
***************
*** 420,436 ****
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"mysql_%s_%s_%s",SAFE_STRING(host), SAFE_STRING(user),
SAFE_STRING(passwd));
}
-
!
if (host && (tmp=strchr(host,':'))) {
*tmp=0;
tmp++;
! mysql_port = atoi(tmp);
} else {
! mysql_port = MySQL_GLOBAL(php3_mysql_module).default_port;
}
!
if (!MySQL_GLOBAL(php3_mysql_module).allow_persistent) {
persistent=0;
}
--- 428,449 ----
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"mysql_%s_%s_%s",SAFE_STRING(host), SAFE_STRING(user),
SAFE_STRING(passwd));
}
! /* We cannot use mysql_port anymore in windows, need to use
! * mysql_real_connect() to set the port.
! */
if (host && (tmp=strchr(host,':'))) {
*tmp=0;
tmp++;
! port = atoi(tmp);
} else {
! port = MySQL_GLOBAL(php3_mysql_module).default_port;
}
!
! #if MYSQL_VERSION_ID < 32200
! mysql_port = port;
! #endif
!
if (!MySQL_GLOBAL(php3_mysql_module).allow_persistent) {
persistent=0;
}
***************
*** 452,459 ****
RETURN_FALSE;
}
/* create the link */
! mysql = (MYSQL *) malloc(sizeof(MYSQL));
! if (mysql_connect(mysql,host,user,passwd)==NULL) {
php3_error(E_WARNING,mysql_error(mysql));
free(mysql);
efree(hashed_details);
--- 465,477 ----
RETURN_FALSE;
}
/* create the link */
! mysql = (MYSQL *) malloc(sizeof(MYSQL));
! #if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */
! mysql_init(mysql);
! if (mysql_real_connect(mysql,host,user,passwd,NULL,port,NULL,0)==NULL) {
! #else
! if (mysql_connect(mysql,host,user,passwd)==NULL) {
! #endif
php3_error(E_WARNING,mysql_error(mysql));
free(mysql);
efree(hashed_details);
***************
*** 487,493 ****
--- 505,515 ----
#if APACHE
signal(SIGPIPE,handler);
#endif
+ #if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */
+ if (mysql_real_connect(le->ptr,host,user,passwd,NULL,port,NULL,0)==NULL) {
+ #else
if (mysql_connect(le->ptr,host,user,passwd)==NULL) {
+ #endif
php3_error(E_WARNING,"MySQL: Link to server lost, unable to reconnect");
_php3_hash_del(plist, hashed_details, hashed_details_length+1);
efree(hashed_details);
***************
*** 532,540 ****
efree(hashed_details);
RETURN_FALSE;
}
mysql = (MYSQL *) emalloc(sizeof(MYSQL));
if (mysql_connect(mysql,host,user,passwd)==NULL) {
! php3_error(E_WARNING,mysql_error(mysql));
efree(hashed_details);
efree(mysql);
RETURN_FALSE;
--- 554,568 ----
efree(hashed_details);
RETURN_FALSE;
}
+
mysql = (MYSQL *) emalloc(sizeof(MYSQL));
+ #if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */
+ mysql_init(mysql);
+ if (mysql_real_connect(mysql,host,user,passwd,NULL,port,NULL,0)==NULL) {
+ #else
if (mysql_connect(mysql,host,user,passwd)==NULL) {
! #endif
! php3_error(E_WARNING,"MySQL Connection Failed: %s\n",mysql_error(mysql));
efree(hashed_details);
efree(mysql);
RETURN_FALSE;
***************
*** 543,549 ****
/* add it to the list */
return_value->value.lval = php3_list_insert(mysql,MySQL_GLOBAL(php3_mysql_module).le_link);
return_value->type = IS_LONG;
!
/* add it to the hash */
new_index_ptr.ptr = (void *) return_value->value.lval;
new_index_ptr.type = le_index_ptr;
--- 571,577 ----
/* add it to the list */
return_value->value.lval = php3_list_insert(mysql,MySQL_GLOBAL(php3_mysql_module).le_link);
return_value->type = IS_LONG;
!
/* add it to the hash */
new_index_ptr.ptr = (void *) return_value->value.lval;
new_index_ptr.type = le_index_ptr;
***************
*** 553,558 ****
--- 581,587 ----
}
MySQL_GLOBAL(php3_mysql_module).num_links++;
}
+
efree(hashed_details);
MySQL_GLOBAL(php3_mysql_module).default_link=return_value->value.lval;
}
***************
*** 785,793 ****
--- 814,829 ----
}
convert_to_string(query);
+ /* mysql_query binary unsafe, use mysql_real_query */
+ #if MYSQL_VERSION_ID > 32199
+ if (mysql_real_query(mysql,query->value.str.val,query->value.str.len)!=0) {
+ RETURN_FALSE;
+ }
+ #else
if (mysql_query(mysql,query->value.str.val)!=0) {
RETURN_FALSE;
}
+ #endif
if ((mysql_result=mysql_store_result(mysql))==NULL) {
/*php3_error(E_WARNING,"Unable to save MySQL query result");
RETURN_FALSE;
***************
*** 841,849 ****
--- 877,892 ----
}
convert_to_string(query);
+ /* mysql_query is binary unsafe, use mysql_real_query */
+ #if MYSQL_VERSION_ID > 32199
+ if (mysql_real_query(mysql,query->value.str.val,query->value.str.len)!=0) {
+ RETURN_FALSE;
+ }
+ #else
if (mysql_query(mysql,query->value.str.val)!=0) {
RETURN_FALSE;
}
+ #endif
if ((mysql_result=mysql_store_result(mysql))==NULL) {
/*
php3_error(E_WARNING,"Unable to save MySQL query result");
***************
*** 1102,1108 ****
RETURN_FALSE;
}
! return_value->value.lval = mysql_affected_rows(mysql);
return_value->type = IS_LONG;
}
--- 1145,1152 ----
RETURN_FALSE;
}
! /* conversion from int64 to long happing here */
! return_value->value.lval = (long)mysql_affected_rows(mysql);
return_value->type = IS_LONG;
}
***************
*** 1137,1143 ****
RETURN_FALSE;
}
! return_value->value.lval = mysql_insert_id(mysql);
return_value->type = IS_LONG;
}
--- 1181,1188 ----
RETURN_FALSE;
}
! /* conversion from int64 to long happing here */
! return_value->value.lval = (long)mysql_insert_id(mysql);
return_value->type = IS_LONG;
}
***************
*** 1273,1279 ****
RETURN_FALSE;
}
! return_value->value.lval = mysql_num_rows(mysql_result);
return_value->type = IS_LONG;
}
--- 1318,1325 ----
RETURN_FALSE;
}
! /* conversion from int64 to long happing here */
! return_value->value.lval = (long)mysql_num_rows(mysql_result);
return_value->type = IS_LONG;
}
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net