1--TEST--
2References to result sets
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once('connect.inc');
11    require_once('table.inc');
12
13    $references = array();
14
15    if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
16            !($res = mysqli_store_result($link)))
17        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
18
19    $idx = 0;
20    while ($row = mysqli_fetch_assoc($res)) {
21        /* mysqlnd: force separation - create copies */
22        $references[$idx] = array(
23            'id' 		=> &$row['id'],
24            'label'	=> $row['label'] . '');
25        $references[$idx++]['id'] += 0;
26    }
27
28    mysqli_close($link);
29
30    mysqli_data_seek($res, 0);
31    while ($row = mysqli_fetch_assoc($res)) {
32        /* mysqlnd: force separation - create copies */
33        $references[$idx] = array(
34            'id' 		=> &$row['id'],
35            'label'	=> $row['label'] . '');
36        $references[$idx++]['id'] += 0;
37    }
38
39    mysqli_free_result($res);
40
41    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
42        printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
43            $host, $user, $db, $port, $socket);
44
45    if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
46            !($res = mysqli_use_result($link)))
47        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
48
49    while ($row = mysqli_fetch_assoc($res)) {
50        /* mysqlnd: force separation - create copies*/
51        $references[$idx] = array(
52            'id' 		=> &$row['id'],
53            'label'	=> $row['label'] . '');
54        $references[$idx]['id2'] = &$references[$idx]['id'];
55        $references[$idx]['id'] += 1;
56        $references[$idx++]['id2'] += 1;
57    }
58
59    $references[$idx++] = &$res;
60    mysqli_free_result($res);
61
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