mysqli_result_references_mysqlnd.phpt 3.1 KB

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