PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 128 lines | 102 code | 25 blank | 1 comment | 11 complexity | a70148ac9f6577645a9f183acf6dddbe 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('connect.inc');
  3. $test_table_name = 'test_mysqli_class_mysqli_stmt_interface_table_1'; require('table.inc');
  4. $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
  5. $stmt = new mysqli_stmt($link);
  6. printf("Parent class:\n");
  7. var_dump(get_parent_class($stmt));
  8. printf("\nMethods:\n");
  9. $methods = get_class_methods($stmt);
  10. $expected_methods = array(
  11. '__construct' => true,
  12. 'attr_get' => true,
  13. 'attr_set' => true,
  14. 'bind_param' => true,
  15. 'bind_result' => true,
  16. 'close' => true,
  17. 'data_seek' => true,
  18. 'execute' => true,
  19. 'fetch' => true,
  20. 'free_result' => true,
  21. 'get_warnings' => true,
  22. 'num_rows' => true,
  23. 'prepare' => true,
  24. 'reset' => true,
  25. 'result_metadata' => true,
  26. 'send_long_data' => true,
  27. 'store_result' => true,
  28. );
  29. if ($IS_MYSQLND) {
  30. $expected_methods['get_result'] = true;
  31. $expected_methods['more_results'] = true;
  32. $expected_methods['next_result'] = true;
  33. }
  34. foreach ($methods as $k => $method) {
  35. if (isset($expected_methods[$method])) {
  36. unset($methods[$k]);
  37. unset($expected_methods[$method]);
  38. }
  39. if ($method == 'mysqli_stmt') {
  40. // get_class_method reports different constructor names
  41. unset($expected_methods['__construct']);
  42. unset($methods[$k]);
  43. }
  44. }
  45. if (!empty($methods)) {
  46. printf("More methods found than indicated. Dumping list of unexpected methods.\n");
  47. var_dump($methods);
  48. }
  49. if (!empty($expected_methods)) {
  50. printf("Some methods are missing. Dumping list of missing methods.\n");
  51. var_dump($expected_methods);
  52. }
  53. if (empty($methods) && empty($expected_methods))
  54. printf("ok\n");
  55. printf("\nClass variables:\n");
  56. $variables = array_keys(get_class_vars(get_class($stmt)));
  57. sort($variables);
  58. foreach ($variables as $k => $var)
  59. printf("%s\n", $var);
  60. printf("\nObject variables:\n");
  61. $variables = array_keys(get_object_vars($stmt));
  62. foreach ($variables as $k => $var)
  63. printf("%s\n", $var);
  64. printf("\nMagic, magic properties:\n");
  65. assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
  66. printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
  67. if (!$stmt->prepare("INSERT INTO test_mysqli_class_mysqli_stmt_interface_table_1(id, label) VALUES (100, 'z')") ||
  68. !$stmt->execute())
  69. printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
  70. assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
  71. printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
  72. assert(mysqli_stmt_errno($stmt) === $stmt->errno);
  73. printf("stmt->errno = '%s'\n", $stmt->errno);
  74. assert(mysqli_stmt_error($stmt) === $stmt->error);
  75. printf("stmt->error = '%s'\n", $stmt->error);
  76. assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
  77. var_dump("stmt->error = ", $stmt->error_list);
  78. assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
  79. printf("stmt->field_count = '%s'\n", $stmt->field_count);
  80. assert($stmt->id > 0);
  81. printf("stmt->id = '%s'\n", $stmt->id);
  82. assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
  83. printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
  84. assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
  85. printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
  86. assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
  87. printf("stmt->param_count = '%s'\n", $stmt->param_count);
  88. assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
  89. printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
  90. printf("\nAccess to undefined properties:\n");
  91. printf("stmt->unknown = '%s'\n", @$stmt->unknown);
  92. @$stmt->unknown = 13;
  93. printf("stmt->unknown = '%s'\n", @$stmt->unknown);
  94. printf("\nPrepare using the constructor:\n");
  95. $stmt = new mysqli_stmt($link, 'SELECT id FROM test_mysqli_class_mysqli_stmt_interface_table_1 ORDER BY id');
  96. if (!$stmt->execute())
  97. printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
  98. $stmt->close();
  99. $obj = new stdClass();
  100. if (!is_object($stmt = new mysqli_stmt($link, $obj)))
  101. printf("[003] Expecting NULL got %s/%s\n", gettype($stmt), $stmt);
  102. print "done!";
  103. ?>