mysqli_stmt_result_metadata.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. --TEST--
  2. mysqli_stmt_result_metadata()
  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. $tmp = NULL;
  13. $link = NULL;
  14. if (!is_null($tmp = @mysqli_stmt_result_metadata()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_stmt_result_metadata($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. if (!$stmt = mysqli_stmt_init($link))
  20. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt)))
  22. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
  24. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  25. if (!is_object(($res = mysqli_stmt_result_metadata($stmt))))
  26. printf("[006] Expecting object, got %s/%s\n", gettype($tmp), $tmp);
  27. if (2 !== ($tmp = mysqli_num_fields($res)))
  28. printf("[007] Expecting int/2, got %s/%s, [%d] %s\n",
  29. gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  30. if (!is_object($field0_fetch = mysqli_fetch_field($res)))
  31. printf("[008] Expecting object, got %s/%s, [%d] %s\n",
  32. gettype($field0_fetch), $field0_fetch, mysqli_errno($link), mysqli_error($link));
  33. if (!is_object($field0_direct = mysqli_fetch_field_direct($res, 0)))
  34. printf("[009] Expecting object, got %s/%s, [%d] %s\n",
  35. gettype($field0_direct), $field0_direct, mysqli_errno($link), mysqli_error($link));
  36. if ($field0_fetch != $field0_direct) {
  37. printf("[010] mysqli_fetch_field() differs from mysqli_fetch_field_direct()\n");
  38. var_dump($field0_fetch);
  39. var_dump($field0_direct);
  40. }
  41. var_dump($field0_fetch);
  42. if (!is_array($tmp = mysqli_fetch_fields($res)))
  43. printf("[011] Expecting array, got %s/%s, [%d] %s\n",
  44. gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  45. if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
  46. printf("[012] mysqli_fetch_fields() return value is suspicious\n");
  47. var_dump($tmp);
  48. }
  49. if (!mysqli_field_seek($res, 1))
  50. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  51. if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1)))
  52. printf("[014] Expecting object, got %s/%s, [%d] %s\n",
  53. gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
  54. if ($tmp[1] != $field1_direct) {
  55. printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
  56. var_dump($field1_direct);
  57. var_dump($tmp);
  58. }
  59. if (1 !== ($tmp = mysqli_field_tell($res)))
  60. printf("[016] Expecting int/1, got %s/%s, [%d] %s\n",
  61. gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  62. mysqli_free_result($res);
  63. mysqli_stmt_close($stmt);
  64. if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt)))
  65. printf("[017] Expecting NULL, got %s/%s\n");
  66. /* Check that the function alias exists. It's a deprecated function,
  67. but we have not announce the removal so far, therefore we need to check for it */
  68. if (!is_null($tmp = @mysqli_stmt_result_metadata()))
  69. printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  70. mysqli_close($link);
  71. print "done!";
  72. ?>
  73. --CLEAN--
  74. <?php
  75. require_once("clean_table.inc");
  76. ?>
  77. --EXPECTF--
  78. Warning: mysqli_stmt_result_metadata(): invalid object or resource mysqli_stmt
  79. in %s on line %d
  80. object(stdClass)#5 (13) {
  81. [%u|b%"name"]=>
  82. %unicode|string%(2) "id"
  83. [%u|b%"orgname"]=>
  84. %unicode|string%(2) "id"
  85. [%u|b%"table"]=>
  86. %unicode|string%(4) "test"
  87. [%u|b%"orgtable"]=>
  88. %unicode|string%(4) "test"
  89. [%u|b%"def"]=>
  90. %unicode|string%(0) ""
  91. [%u|b%"db"]=>
  92. %unicode|string%(%d) "%s"
  93. [%u|b%"catalog"]=>
  94. %unicode|string%(%d) "%s"
  95. [%u|b%"max_length"]=>
  96. int(0)
  97. [%u|b%"length"]=>
  98. int(11)
  99. [%u|b%"charsetnr"]=>
  100. int(63)
  101. [%u|b%"flags"]=>
  102. int(49155)
  103. [%u|b%"type"]=>
  104. int(3)
  105. [%u|b%"decimals"]=>
  106. int(0)
  107. }
  108. Warning: mysqli_stmt_result_metadata(): Couldn't fetch mysqli_stmt in %s on line %d
  109. done!