mysqli_result_references.phpt 3.6 KB

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