was global and not per connection.
- use ecalloc() instead of calloc() for memory that will be freed with
efree()
}
}
- mysql = (MY_MYSQL *)calloc(1, sizeof(MY_MYSQL));
+ mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL));
if (!(mysql->mysql = mysql_init(NULL))) {
efree(mysql);
return;
}
- mysql = (MY_MYSQL *) calloc(1, sizeof(MY_MYSQL));
+ mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
if (!(mysql = mysql_init(NULL))) {
efree(mysql);
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;
MYSQL *mysql;
zval *li_read;
php_stream *li_stream;
+ unsigned int multi_query;
} MY_MYSQL;
typedef struct {
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) { \
char *error_msg;
int report_mode;
HashTable *report_ht;
- unsigned int multi_query;
#ifdef HAVE_EMBEDDED_MYSQLI
unsigned int embedded;
#endif
--- /dev/null
+--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)