mysqli_result_references_mysqlnd.phpt 2.7 KB

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