mysqli_fetch_column.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. --TEST--
  2. mysqli_fetch_column()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once 'skipifconnectfailure.inc';
  8. if (!$IS_MYSQLND) {
  9. die("skip mysqlnd only test");
  10. }
  11. ?>
  12. --FILE--
  13. <?php
  14. require_once "connect.inc";
  15. require 'table.inc';
  16. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  17. $res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1");
  18. print "[001]\n";
  19. var_dump(mysqli_fetch_column($res));
  20. print "[002]\n";
  21. var_dump(mysqli_fetch_column($res));
  22. $link->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
  23. $res = mysqli_query($link, "SELECT
  24. 1 AS a,
  25. 2 AS a
  26. ");
  27. print "[003]\n";
  28. var_dump(mysqli_fetch_column($res, 0));
  29. $res = mysqli_query($link, "SELECT
  30. 1 AS a,
  31. 2 AS a
  32. ");
  33. print "[004]\n";
  34. var_dump(mysqli_fetch_column($res, 1));
  35. $res = mysqli_query($link, "SELECT
  36. 1 AS a,
  37. 2 AS a,
  38. 3
  39. ");
  40. print "[005]\n";
  41. var_dump(mysqli_fetch_column($res, 2));
  42. $res = mysqli_query($link, "SELECT
  43. 1 AS a,
  44. 2 AS a,
  45. 3,
  46. NULL AS d
  47. ");
  48. print "[006]\n";
  49. var_dump(mysqli_fetch_column($res, 3));
  50. $res = mysqli_query($link, "SELECT
  51. 1 AS a,
  52. 2 AS a,
  53. 3,
  54. NULL AS d,
  55. true AS e
  56. ");
  57. print "[007]\n";
  58. var_dump(mysqli_fetch_column($res, 4));
  59. $res = mysqli_query($link, "SELECT
  60. 1.42 AS a
  61. ");
  62. print "[008]\n";
  63. var_dump(mysqli_fetch_column($res, 0));
  64. $res = mysqli_query($link, "SELECT
  65. 1.42E0 AS a
  66. ");
  67. print "[009]\n";
  68. var_dump(mysqli_fetch_column($res, 0));
  69. $res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1");
  70. print "[010]\n";
  71. try {
  72. var_dump(mysqli_fetch_column($res, -1));
  73. } catch (\ValueError $e) {
  74. echo $e->getMessage(), \PHP_EOL;
  75. }
  76. $res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1");
  77. print "[011]\n";
  78. try {
  79. var_dump(mysqli_fetch_column($res, 2));
  80. } catch (\ValueError $e) {
  81. echo $e->getMessage(), \PHP_EOL;
  82. }
  83. mysqli_free_result($res);
  84. try {
  85. mysqli_fetch_column($res);
  86. } catch (Error $exception) {
  87. echo $exception->getMessage() . "\n";
  88. }
  89. $res = $link->query("SELECT id, label FROM test ORDER BY id LIMIT 2");
  90. print "[012]\n";
  91. var_dump($res->fetch_column());
  92. print "[013]\n";
  93. var_dump($res->fetch_column(1));
  94. mysqli_close($link);
  95. ?>
  96. --CLEAN--
  97. <?php
  98. require_once "clean_table.inc";
  99. ?>
  100. --EXPECT--
  101. [001]
  102. string(1) "1"
  103. [002]
  104. bool(false)
  105. [003]
  106. int(1)
  107. [004]
  108. int(2)
  109. [005]
  110. int(3)
  111. [006]
  112. NULL
  113. [007]
  114. int(1)
  115. [008]
  116. string(4) "1.42"
  117. [009]
  118. float(1.42)
  119. [010]
  120. mysqli_fetch_column(): Argument #2 ($column) must be greater than or equal to 0
  121. [011]
  122. mysqli_fetch_column(): Argument #2 ($column) must be less than the number of fields for this result set
  123. mysqli_result object is already closed
  124. [012]
  125. int(1)
  126. [013]
  127. string(1) "b"