]> granicus.if.org Git - php/commitdiff
- Fix bug 31668 (multi query fails every other time). The multi_query flag
authorAndrey Hristov <andrey@php.net>
Wed, 27 Apr 2005 12:03:05 +0000 (12:03 +0000)
committerAndrey Hristov <andrey@php.net>
Wed, 27 Apr 2005 12:03:05 +0000 (12:03 +0000)
  was global and not per connection.
- use ecalloc() instead of calloc() for memory that will be freed with
  efree()

ext/mysqli/mysqli_nonapi.c
ext/mysqli/php_mysqli.h
ext/mysqli/tests/bug31668.phpt [new file with mode: 0644]

index 9d00745bf93cff0a3d8b2d5a09cc932a60c70e7c..8fa90316fd73659e686ed0998fc788ae94c99aac 100644 (file)
@@ -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;
index dfd4f6cd4c0e1f6a973b1cf5dd03584491153a8a..4eff2757b84fb4a99c4c460fbc2a5b49908dd97d 100644 (file)
@@ -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 (file)
index 0000000..b813096
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+Bug #31668 multi_query works exactly every other time (multi_query was global, now per connection)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+       include "connect.inc";
+
+       $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__);
+       $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)