1--TEST--
2References to result sets
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once('connect.inc');
12    require_once('table.inc');
13
14    $references = array();
15
16    if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
17            !($res = mysqli_store_result($link)))
18        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
19
20    $idx = 0;
21    while ($row = mysqli_fetch_assoc($res)) {
22        /* mysqlnd: force separation - create copies */
23        $references[$idx] = array(
24            'id' 		=> &$row['id'],
25            'label'	=> $row['label'] . '');
26        $references[$idx++]['id'] += 0;
27    }
28
29    mysqli_close($link);
30
31    mysqli_data_seek($res, 0);
32    while ($row = mysqli_fetch_assoc($res)) {
33        /* mysqlnd: force separation - create copies */
34        $references[$idx] = array(
35            'id' 		=> &$row['id'],
36            'label'	=> $row['label'] . '');
37        $references[$idx++]['id'] += 0;
38    }
39
40    mysqli_free_result($res);
41
42    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
43        printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
44            $host, $user, $db, $port, $socket);
45
46    if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
47            !($res = mysqli_use_result($link)))
48        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
49
50    while ($row = mysqli_fetch_assoc($res)) {
51        /* mysqlnd: force separation - create copies*/
52        $references[$idx] = array(
53            'id' 		=> &$row['id'],
54            'label'	=> $row['label'] . '');
55        $references[$idx]['id2'] = &$references[$idx]['id'];
56        $references[$idx]['id'] += 1;
57        $references[$idx++]['id2'] += 1;
58    }
59
60    $references[$idx++] = &$res;
61    mysqli_free_result($res);
62    debug_zval_dump($references);
63
64    if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
65            !($res = mysqli_use_result($link)))
66        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
67
68    $tmp = array();
69    while ($row = mysqli_fetch_assoc($res)) {
70        $tmp[] = $row;
71    }
72    $tmp = unserialize(serialize($tmp));
73    debug_zval_dump($tmp);
74    mysqli_free_result($res);
75
76    mysqli_close($link);
77    print "done!";
78?>
79--CLEAN--
80<?php
81    require_once("clean_table.inc");
82?>
83--EXPECTF--
84array(7) refcount(2){
85  [0]=>
86  array(2) refcount(1){
87    ["id"]=>
88    int(1)
89    ["label"]=>
90    string(1) "a" refcount(%d)
91  }
92  [1]=>
93  array(2) refcount(1){
94    ["id"]=>
95    int(2)
96    ["label"]=>
97    string(1) "b" refcount(%d)
98  }
99  [2]=>
100  array(2) refcount(1){
101    ["id"]=>
102    int(1)
103    ["label"]=>
104    string(1) "a" refcount(%d)
105  }
106  [3]=>
107  array(2) refcount(1){
108    ["id"]=>
109    int(2)
110    ["label"]=>
111    string(1) "b" refcount(%d)
112  }
113  [4]=>
114  array(3) refcount(1){
115    ["id"]=>
116    &int(3)
117    ["label"]=>
118    string(1) "a" refcount(%d)
119    ["id2"]=>
120    &int(3)
121  }
122  [5]=>
123  array(3) refcount(1){
124    ["id"]=>
125    &int(4)
126    ["label"]=>
127    string(1) "b" refcount(%d)
128    ["id2"]=>
129    &int(4)
130  }
131  [6]=>
132  &object(mysqli_result)#%d (0) refcount(%d){
133  }
134}
135array(1) refcount(2){
136  [0]=>
137  array(2) refcount(1){
138    ["id"]=>
139    string(1) "1" refcount(%d)
140    ["label"]=>
141    string(1) "a" refcount(%d)
142  }
143}
144done!
145