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