1--TEST--
2References to result sets - mysqlnd (no copies but references)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8
9require_once('connect.inc');
10if (!$IS_MYSQLND)
11	die("skip Test for mysqlnd only");
12require_once('skipifemb.inc'); ?>
13--FILE--
14<?php
15	require_once('connect.inc');
16	require_once('table.inc');
17
18	$references = array();
19
20	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
21			!($res = mysqli_store_result($link)))
22		printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24	$idx = 0;
25	while ($row = mysqli_fetch_assoc($res)) {
26		/* will overwrite itself */
27		$references[$idx]['row_ref'] 		= &$row;
28		$references[$idx]['row_copy'] 	= $row;
29		$references[$idx]['id_ref'] 		= &$row['id'];
30		$references[$idx++]['id_copy']	= $row['id'];
31	}
32
33	debug_zval_dump($references);
34	mysqli_free_result($res);
35
36	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
37			!($res = mysqli_use_result($link)))
38		printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
39
40	$rows = array();
41	for ($i = 0; $i < 2; $i++) {
42		$rows[$i] = mysqli_fetch_assoc($res);
43		$references[$idx]['row_ref'] 		= &$rows[$i];
44		$references[$idx]['row_copy'] 	= $rows[$i];
45		$references[$idx]['id_ref'] 		= &$rows[$i]['id'];
46		$references[$idx]['id_copy']		= $rows[$i]['id'];
47		/* enforce separation */
48		$references[$idx]['id_copy_mod']= $rows[$i]['id'] + 0;
49	}
50	mysqli_free_result($res);
51
52	debug_zval_dump($references);
53	print "done!";
54?>
55--EXPECTF--
56array(1) refcount(%d){
57  [0]=>
58  array(4) refcount(%d){
59    ["row_ref"]=>
60    &NULL
61    ["row_copy"]=>
62    array(2) refcount(1){
63      ["id"]=>
64      string(1) "1" refcount(%d)
65      ["label"]=>
66      string(1) "a" refcount(%d)
67    }
68    ["id_ref"]=>
69    string(1) "1" refcount(%d)
70    ["id_copy"]=>
71    string(1) "1" refcount(%d)
72  }
73}
74array(2) refcount(%d){
75  [0]=>
76  array(4) refcount(%d){
77    ["row_ref"]=>
78    &NULL
79    ["row_copy"]=>
80    array(2) refcount(%d){
81      ["id"]=>
82      string(1) "1" refcount(%d)
83      ["label"]=>
84      string(1) "a" refcount(%d)
85    }
86    ["id_ref"]=>
87    string(1) "1" refcount(%d)
88    ["id_copy"]=>
89    string(1) "1" refcount(%d)
90  }
91  [1]=>
92  array(5) refcount(%d){
93    ["row_ref"]=>
94    &array(2) refcount(%d){
95      ["id"]=>
96      &string(1) "2" refcount(%d)
97      ["label"]=>
98      string(1) "b" refcount(%d)
99    }
100    ["row_copy"]=>
101    array(2) refcount(%d){
102      ["id"]=>
103      string(1) "2" refcount(%d)
104      ["label"]=>
105      string(1) "b" refcount(%d)
106    }
107    ["id_ref"]=>
108    &string(1) "2" refcount(%d)
109    ["id_copy"]=>
110    string(1) "2" refcount(%d)
111    ["id_copy_mod"]=>
112    int(2)
113  }
114}
115done!
116