From: Andrey Hristov Date: Wed, 27 Apr 2005 12:03:05 +0000 (+0000) Subject: - Fix bug 31668 (multi query fails every other time). The multi_query flag X-Git-Tag: php-5.0.5RC1~369 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8595c6b6b8a9783e5f18a4c5fdbac061d73406b7;p=php - Fix bug 31668 (multi query fails every other time). The multi_query flag was global and not per connection. - use ecalloc() instead of calloc() for memory that will be freed with efree() --- diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 9d00745bf9..8fa90316fd 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -67,7 +67,7 @@ PHP_FUNCTION(mysqli_connect) } } - mysql = (MY_MYSQL *)calloc(1, sizeof(MY_MYSQL)); + mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL)); if (!(mysql->mysql = mysql_init(NULL))) { efree(mysql); @@ -132,7 +132,7 @@ PHP_FUNCTION(mysqli_embedded_connect) return; } - mysql = (MY_MYSQL *) calloc(1, sizeof(MY_MYSQL)); + mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL)); if (!(mysql = mysql_init(NULL))) { efree(mysql); @@ -217,7 +217,7 @@ PHP_FUNCTION(mysqli_multi_query) MY_MYSQL *mysql; zval *mysql_link; char *query = NULL; - unsigned int query_len; + unsigned long query_len; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) { return; diff --git a/ext/mysqli/php_mysqli.h b/ext/mysqli/php_mysqli.h index dfd4f6cd4c..4eff2757b8 100644 --- a/ext/mysqli/php_mysqli.h +++ b/ext/mysqli/php_mysqli.h @@ -55,6 +55,7 @@ typedef struct { MYSQL *mysql; zval *li_read; php_stream *li_stream; + unsigned int multi_query; } MY_MYSQL; typedef struct { @@ -131,14 +132,14 @@ zend_class_entry _mysqli_result_class_entry; PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRMLS_DC); -#define MYSQLI_DISABLE_MQ if (MyG(multi_query)) { \ +#define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \ - MyG(multi_query) = 0; \ + mysql->multi_query = 0; \ } -#define MYSQLI_ENABLE_MQ if (!MyG(multi_query)) { \ +#define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \ mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \ - MyG(multi_query) = 1; \ + mysql->multi_query = 1; \ } #define REGISTER_MYSQLI_CLASS_ENTRY(name, mysqli_entry, class_functions) { \ @@ -386,7 +387,6 @@ ZEND_BEGIN_MODULE_GLOBALS(mysqli) char *error_msg; int report_mode; HashTable *report_ht; - unsigned int multi_query; #ifdef HAVE_EMBEDDED_MYSQLI unsigned int embedded; #endif diff --git a/ext/mysqli/tests/bug31668.phpt b/ext/mysqli/tests/bug31668.phpt new file mode 100644 index 0000000000..b813096a2a --- /dev/null +++ b/ext/mysqli/tests/bug31668.phpt @@ -0,0 +1,56 @@ +--TEST-- +Bug #31668 multi_query works exactly every other time (multi_query was global, now per connection) +--SKIPIF-- + +--FILE-- +multi_query('SELECT 1;SELECT 2'); + do { + $res = $mysql->store_result(); + if ($mysql->errno == 0) { + while ($arr = $res->fetch_assoc()) { + var_dump($arr); + } + $res->free(); + } + } while ($mysql->next_result()); + var_dump($mysql->error, __LINE__); + $mysql->close(); + + $mysql = new mysqli($host, $user, $passwd, "test"); + $mysql->multi_query('SELECT 1;SELECT 2'); + do { + $res = $mysql->store_result(); + if ($mysql->errno == 0) { + while ($arr = $res->fetch_assoc()) { + var_dump($arr); + } + $res->free(); + } + } while ($mysql->next_result()); + var_dump($mysql->error, __LINE__); +?> +--EXPECTF-- +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [2]=> + string(1) "2" +} +string(0) "" +int(%d) +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [2]=> + string(1) "2" +} +string(0) "" +int(%d)