PageRenderTime 153ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_stmt_field_count.php

http://github.com/facebook/hiphop-php
PHP | 71 lines | 56 code | 15 blank | 0 comment | 21 complexity | ecacbf0bf86ef025018335fc467e8afb MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. require_once("connect.inc");
  3. $tmp = NULL;
  4. $link = NULL;
  5. $test_table_name = 'test_mysqli_stmt_field_count_table_1'; require('table.inc');
  6. $stmt = mysqli_stmt_init($link);
  7. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  8. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  9. if (mysqli_stmt_prepare($stmt, ''))
  10. printf("[004] Prepare should fail for an empty statement\n");
  11. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  12. printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  13. if (!mysqli_stmt_prepare($stmt, 'SELECT 1'))
  14. printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  15. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  16. printf("[007] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!mysqli_stmt_prepare($stmt, 'SELECT 1, 2'))
  18. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  19. if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
  20. printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test_mysqli_stmt_field_count_table_1'))
  22. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  23. if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
  24. printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
  25. if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test_mysqli_stmt_field_count_table_1') ||
  26. !mysqli_stmt_execute($stmt))
  27. printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  28. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  29. printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  30. $label = null;
  31. if (mysqli_stmt_bind_param($stmt, "s", $label))
  32. printf("[014] expected error - got ok\n");
  33. while (mysqli_stmt_fetch($stmt))
  34. if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
  35. printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
  36. if (!mysqli_stmt_prepare($stmt, 'INSERT INTO test_mysqli_stmt_field_count_table_1(id) VALUES (100)'))
  37. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  38. if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
  39. printf("[017] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  40. if (!mysqli_stmt_prepare($stmt, "UPDATE test_mysqli_stmt_field_count_table_1 SET label = 'z' WHERE id = 1") ||
  41. !mysqli_stmt_execute($stmt))
  42. printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  43. if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
  44. printf("[019] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  45. mysqli_stmt_close($stmt);
  46. if (mysqli_stmt_prepare($stmt, 'SELECT id FROM test_mysqli_stmt_field_count_table_1'))
  47. printf("[020] Prepare should fail, statement has been closed\n");
  48. if (!is_null($tmp = mysqli_stmt_field_count($stmt)))
  49. printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  50. mysqli_close($link);
  51. print "done!";
  52. ?>
  53. <?php error_reporting(0); ?>
  54. <?php
  55. $test_table_name = 'test_mysqli_stmt_field_count_table_1'; require_once("clean_table.inc");
  56. ?>