mysqli_stmt_param_count.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. mysqli_stmt_param_count()
  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_param_count()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_stmt_param_count($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 (false !== ($tmp = mysqli_stmt_param_count($stmt)))
  22. printf("[004] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
  23. function func_test_mysqli_stmt_param_count($stmt, $query, $expected, $offset) {
  24. if (!mysqli_stmt_prepare($stmt, $query)) {
  25. printf("[%03d] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_error($stmt));
  26. return false;
  27. }
  28. if ($expected !== ($tmp = mysqli_stmt_param_count($stmt)))
  29. printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 3,
  30. gettype($expected), $expected,
  31. gettype($tmp), $tmp);
  32. return true;
  33. }
  34. func_test_mysqli_stmt_param_count($stmt, "SELECT 1 AS a", 0, 10);
  35. func_test_mysqli_stmt_param_count($stmt, "INSERT INTO test(id) VALUES (?)", 1, 20);
  36. func_test_mysqli_stmt_param_count($stmt, "INSERT INTO test(id, label) VALUES (?, ?)", 2, 30);
  37. func_test_mysqli_stmt_param_count($stmt, "INSERT INTO test(id, label) VALUES (?, '?')", 1, 40);
  38. mysqli_stmt_close($stmt);
  39. if (false !== ($tmp = mysqli_stmt_param_count($stmt)))
  40. printf("[40] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
  41. mysqli_close($link);
  42. /* Check that the function alias exists. It's a deprecated function,
  43. but we have not announce the removal so far, therefore we need to check for it */
  44. if (!is_null($tmp = @mysqli_stmt_param_count()))
  45. printf("[041] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  46. print "done!";
  47. ?>
  48. --CLEAN--
  49. <?php
  50. require_once("clean_table.inc");
  51. ?>
  52. --EXPECTF--
  53. Warning: mysqli_stmt_param_count(): invalid object or resource mysqli_stmt
  54. in %s on line %d
  55. Warning: mysqli_stmt_param_count(): Couldn't fetch mysqli_stmt in %s on line %d
  56. done!