Hi,
The attached patch against current CVS adds an optional
parameter to mysql_connect() to specify if a truly new link
to the database should be established. The patch changes the
prototype to:
resource mysql_connect ([string hostname [, string username [, string password [,
bool new_link ]]]]);
There is no BC issue. The optional parameter is ignored when
using mysql_pconnect().
FYI: This is what a few people have complained about in the
past and there are existing Bu^H^HFeature Requests for this
behaviour (can't find them right now, too late).
Example old hevaiour (will fail):
<?
$link1 = mysql_connect('ficken', 'phptest1', 'phptest1');
mysql_select_db('phptest1', $link1);
$result = mysql_query("SELECT * FROM php", $link1);
var_dump($result);
$link2 = mysql_connect('ficken', 'phptest1', 'phptest1');
mysql_select_db('phptest2', $link2);
$result = mysql_query("SELECT * FROM perl", $link2);
var_dump($result);
$result = mysql_query("SELECT * FROM php", $link1);
var_dump($result);
?>
Example new behaviour (works):
<?
$link1 = mysql_connect('ficken', 'phptest1', 'phptest1');
mysql_select_db('phptest1', $link1);
$result = mysql_query("SELECT * FROM php", $link1);
var_dump($result);
$link2 = mysql_connect('ficken', 'phptest1', 'phptest1', true);
^^^^^^^^
mysql_select_db('phptest2', $link2);
$result = mysql_query("SELECT * FROM perl", $link2);
var_dump($result);
$result = mysql_query("SELECT * FROM php", $link1);
var_dump($result);
?>
In the first example, the last query will fail. In the second
it works.
- Markus
? .php_mysql.c.swp
? new_link.diff
Index: php_mysql.c
===================================================================
RCS file: /repository/php4/ext/mysql/php_mysql.c,v
retrieving revision 1.107
diff -u -r1.107 php_mysql.c
--- php_mysql.c 8 Nov 2001 22:05:56 -0000 1.107
+++ php_mysql.c 21 Nov 2001 02:30:51 -0000
@@ -431,8 +431,8 @@
int hashed_details_length, port = MYSQL_PORT;
php_mysql_conn *mysql=NULL;
void (*handler) (int);
- zval **z_host=NULL, **z_user=NULL, **z_passwd=NULL;
- zend_bool free_host=0;
+ zval **z_host=NULL, **z_user=NULL, **z_passwd=NULL, **z_new_link=NULL;
+ zend_bool free_host=0, new_link=0;
socket = MySG(default_socket);
@@ -477,6 +477,17 @@
passwd = Z_STRVAL_PP(z_passwd);
}
break;
+ case 4: {
+ if (zend_get_parameters_ex(4, &z_host,
+&z_user, &z_passwd, &z_new_link) == FAILURE) {
+ MYSQL_DO_CONNECT_RETURN_FALSE();
+ }
+ convert_to_string_ex(z_user);
+ convert_to_string_ex(z_passwd);
+ user = Z_STRVAL_PP(z_user);
+ passwd = Z_STRVAL_PP(z_passwd);
+ new_link = Z_BVAL_PP(z_new_link);
+ }
+ break;
default:
WRONG_PARAM_COUNT;
break;
@@ -612,7 +623,7 @@
* if it doesn't, open a new mysql link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
- if (zend_hash_find(&EG(regular_list), hashed_details,
hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
+ if (!new_link && zend_hash_find(&EG(regular_list), hashed_details,
+hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
int type, link;
void *ptr;
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]