/hphp/test/zend/bad/ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.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
- <?php
- require('connect.inc');
- $test_table_name = 'test_mysqli_class_mysqli_stmt_interface_table_1'; require('table.inc');
- $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
- $stmt = new mysqli_stmt($link);
- printf("Parent class:\n");
- var_dump(get_parent_class($stmt));
- printf("\nMethods:\n");
- $methods = get_class_methods($stmt);
- $expected_methods = array(
- '__construct' => true,
- 'attr_get' => true,
- 'attr_set' => true,
- 'bind_param' => true,
- 'bind_result' => true,
- 'close' => true,
- 'data_seek' => true,
- 'execute' => true,
- 'fetch' => true,
- 'free_result' => true,
- 'get_warnings' => true,
- 'num_rows' => true,
- 'prepare' => true,
- 'reset' => true,
- 'result_metadata' => true,
- 'send_long_data' => true,
- 'store_result' => true,
- );
- if ($IS_MYSQLND) {
- $expected_methods['get_result'] = true;
- $expected_methods['more_results'] = true;
- $expected_methods['next_result'] = true;
- }
- foreach ($methods as $k => $method) {
- if (isset($expected_methods[$method])) {
- unset($methods[$k]);
- unset($expected_methods[$method]);
- }
- if ($method == 'mysqli_stmt') {
- // get_class_method reports different constructor names
- unset($expected_methods['__construct']);
- unset($methods[$k]);
- }
- }
- if (!empty($methods)) {
- printf("More methods found than indicated. Dumping list of unexpected methods.\n");
- var_dump($methods);
- }
- if (!empty($expected_methods)) {
- printf("Some methods are missing. Dumping list of missing methods.\n");
- var_dump($expected_methods);
- }
- if (empty($methods) && empty($expected_methods))
- printf("ok\n");
- printf("\nClass variables:\n");
- $variables = array_keys(get_class_vars(get_class($stmt)));
- sort($variables);
- foreach ($variables as $k => $var)
- printf("%s\n", $var);
- printf("\nObject variables:\n");
- $variables = array_keys(get_object_vars($stmt));
- foreach ($variables as $k => $var)
- printf("%s\n", $var);
- printf("\nMagic, magic properties:\n");
- assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
- printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
- if (!$stmt->prepare("INSERT INTO test_mysqli_class_mysqli_stmt_interface_table_1(id, label) VALUES (100, 'z')") ||
- !$stmt->execute())
- printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
- assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
- printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
- assert(mysqli_stmt_errno($stmt) === $stmt->errno);
- printf("stmt->errno = '%s'\n", $stmt->errno);
- assert(mysqli_stmt_error($stmt) === $stmt->error);
- printf("stmt->error = '%s'\n", $stmt->error);
- assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
- var_dump("stmt->error = ", $stmt->error_list);
- assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
- printf("stmt->field_count = '%s'\n", $stmt->field_count);
- assert($stmt->id > 0);
- printf("stmt->id = '%s'\n", $stmt->id);
- assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
- printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
- assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
- printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
- assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
- printf("stmt->param_count = '%s'\n", $stmt->param_count);
- assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
- printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
- printf("\nAccess to undefined properties:\n");
- printf("stmt->unknown = '%s'\n", @$stmt->unknown);
- @$stmt->unknown = 13;
- printf("stmt->unknown = '%s'\n", @$stmt->unknown);
- printf("\nPrepare using the constructor:\n");
- $stmt = new mysqli_stmt($link, 'SELECT id FROM test_mysqli_class_mysqli_stmt_interface_table_1 ORDER BY id');
- if (!$stmt->execute())
- printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
- $stmt->close();
- $obj = new stdClass();
- if (!is_object($stmt = new mysqli_stmt($link, $obj)))
- printf("[003] Expecting NULL got %s/%s\n", gettype($stmt), $stmt);
- print "done!";
- ?>