mysqli_stmt_field_count.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --TEST--
  2. mysqli_stmt_field_counts()
  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_field_count()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_stmt_field_count($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. $stmt = mysqli_stmt_init($link);
  20. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  21. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  22. if (mysqli_stmt_prepare($stmt, ''))
  23. printf("[004] Prepare should fail for an empty statement\n");
  24. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  25. printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  26. if (!mysqli_stmt_prepare($stmt, 'SELECT 1'))
  27. printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  28. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  29. printf("[007] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  30. if (!mysqli_stmt_prepare($stmt, 'SELECT 1, 2'))
  31. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  32. if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
  33. printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  34. if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test'))
  35. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  36. if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
  37. printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  38. if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test') ||
  39. !mysqli_stmt_execute($stmt))
  40. printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  41. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  42. printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  43. $label = null;
  44. if (mysqli_stmt_bind_param($stmt, "s", $label))
  45. printf("[014] expected error - got ok\n");
  46. while (mysqli_stmt_fetch($stmt))
  47. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  48. printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  49. if (!mysqli_stmt_prepare($stmt, 'INSERT INTO test(id) VALUES (100)'))
  50. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  51. if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
  52. printf("[017] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  53. if (!mysqli_stmt_prepare($stmt, "UPDATE test SET label = 'z' WHERE id = 1") ||
  54. !mysqli_stmt_execute($stmt))
  55. printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  56. if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
  57. printf("[019] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  58. mysqli_stmt_close($stmt);
  59. if (mysqli_stmt_prepare($stmt, 'SELECT id FROM test'))
  60. printf("[020] Prepare should fail, statement has been closed\n");
  61. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  62. printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  63. mysqli_close($link);
  64. print "done!";
  65. ?>
  66. --CLEAN--
  67. <?php
  68. require_once("clean_table.inc");
  69. ?>
  70. --EXPECTF--
  71. Warning: mysqli_stmt_field_count(): invalid object or resource mysqli_stmt
  72. in %s on line %d
  73. Warning: mysqli_stmt_field_count(): invalid object or resource mysqli_stmt
  74. in %s on line %d
  75. Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in %s on line %d
  76. Warning: mysqli_stmt_prepare(): Couldn't fetch mysqli_stmt in %s on line %d
  77. Warning: mysqli_stmt_field_count(): Couldn't fetch mysqli_stmt in %s on line %d
  78. done!