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    [%u|b%"id"]=>
88    long(1) refcount(1)
89    [%u|b%"label"]=>
90    %unicode|string%(1) "a" refcount(1)
91  }
92  [1]=>
93  array(2) refcount(1){
94    [%u|b%"id"]=>
95    long(2) refcount(1)
96    [%u|b%"label"]=>
97    %unicode|string%(1) "b" refcount(1)
98  }
99  [2]=>
100  array(2) refcount(1){
101    [%u|b%"id"]=>
102    long(1) refcount(1)
103    [%u|b%"label"]=>
104    %unicode|string%(1) "a" refcount(1)
105  }
106  [3]=>
107  array(2) refcount(1){
108    [%u|b%"id"]=>
109    long(2) refcount(1)
110    [%u|b%"label"]=>
111    %unicode|string%(1) "b" refcount(1)
112  }
113  [4]=>
114  array(3) refcount(1){
115    [%u|b%"id"]=>
116    &long(3) refcount(2)
117    [%u|b%"label"]=>
118    %unicode|string%(1) "a" refcount(1)
119    [%u|b%"id2"]=>
120    &long(3) refcount(2)
121  }
122  [5]=>
123  array(3) refcount(1){
124    [%u|b%"id"]=>
125    &long(4) refcount(2)
126    [%u|b%"label"]=>
127    %unicode|string%(1) "b" refcount(1)
128    [%u|b%"id2"]=>
129    &long(4) refcount(2)
130  }
131  [6]=>
132  &object(mysqli_result)#2 (5) refcount(2){
133    [%u|b%"current_field"]=>
134    NULL refcount(1)
135    [%u|b%"field_count"]=>
136    NULL refcount(1)
137    [%u|b%"lengths"]=>
138    NULL refcount(1)
139    [%u|b%"num_rows"]=>
140    NULL refcount(1)
141    [%u|b%"type"]=>
142    NULL refcount(1)
143  }
144}
145array(1) refcount(2){
146  [0]=>
147  array(2) refcount(1){
148    [%u|b%"id"]=>
149    %unicode|string%(1) "1" refcount(1)
150    [%u|b%"label"]=>
151    %unicode|string%(1) "a" refcount(1)
152  }
153}
154done!
155