cvs: /php3/functions mysql.c

From: Date: Mon, 27 Dec 1999 19:37:22 +0000
Subject: cvs: /php3/functions mysql.c
Groups: php.dev 
Request: Send a blank email to php-dev+get-14060@lists.php.net to get a copy of this message
rasmus Mon Dec 27 14:37:22 1999 EDT Modified files: /php3/functions mysql.c Log: mysql_change_user support for mysql_pconnect It is simplistic in that I just don't hash the connection details on a pconnect and insted do an implicit change_user on every pconnect if a persistent connection exists. Simple, but I think it should do the trick. Index: php3/functions/mysql.c diff -u php3/functions/mysql.c:1.191 php3/functions/mysql.c:1.192 --- php3/functions/mysql.c:1.191 Sun Dec 26 13:44:47 1999 +++ php3/functions/mysql.c Mon Dec 27 14:37:21 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mysql.c,v 1.191 1999/12/26 18:44:47 rasmus Exp $ */ +/* $Id: mysql.c,v 1.192 1999/12/27 19:37:21 rasmus Exp $ */ /* TODO: @@ -402,9 +402,27 @@ WRONG_PARAM_COUNT; break; } - hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); - 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 we are asking for a persistent connection and have a version of + MySQL that supports the mysql_change_user() call, don't put any of the + connection-specific data into hashed_details. Otherwise, use the old + mechanism. + */ + if(persistent) { +#if MYSQL_VERSION_ID > 32302 + hashed_details_length = sizeof("mysql___")-1; + hashed_details = (char *) emalloc(hashed_details_length+1); + strcpy(hashed_details,"mysql___"); +#else + hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); + hashed_details = (char *) emalloc(hashed_details_length+1); + sprintf(hashed_details,"mysql_%s_%s_%s",SAFE_STRING(host), SAFE_STRING(user), SAFE_STRING(passwd)); +#endif + } else { + hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); + 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 @@ -497,7 +515,16 @@ efree(hashed_details); RETURN_FALSE; } + } +#if MYSQL_VERSION_ID > 32302 + else { + if(mysql_change_user((MYSQL *)le->ptr, user, passwd, NULL)!=0) { + php3_error(E_WARNING,mysql_error((MYSQL *)le->ptr)); + efree(hashed_details); + RETURN_FALSE; + } } +#endif #if APACHE signal(SIGPIPE,handler); #endif

« previous php.dev (#14060) next »