mysqli_result_references.phpt 3.7 KB

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