1--TEST--
2mysqli_stmt_fetch()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    /*
12    NOTE: no datatype tests here! This is done by
13    mysqli_stmt_bind_result.phpt already. Restrict
14    this test case to the basics.
15    */
16    require_once("connect.inc");
17
18    require('table.inc');
19
20    if (!$stmt = mysqli_stmt_init($link))
21        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    // stmt object status test
24    try {
25        mysqli_stmt_fetch($stmt);
26    } catch (Error $exception) {
27        echo $exception->getMessage() . "\n";
28    }
29
30    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
31        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
32
33    // FIXME - different versions return different values ?!
34    if ((NULL !== ($tmp = mysqli_stmt_fetch($stmt))) && (false !== $tmp))
35        printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), $tmp);
36
37    if (!mysqli_stmt_execute($stmt))
38        printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
39
40    if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
41        printf("[008] NULL, got %s/%s\n", gettype($tmp), $tmp);
42
43    mysqli_stmt_close($stmt);
44    if (!$stmt = mysqli_stmt_init($link))
45        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
46
47    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
48        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
49
50    if (!mysqli_stmt_execute($stmt))
51        printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
52
53    $id = NULL;
54    $label = NULL;
55    if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
56        printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
57
58    if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
59        printf("[013] Expecting boolean/true, got %s/%s, [%d] %s\n",
60            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62    if (!mysqli_kill($link, mysqli_thread_id($link)))
63        printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
64
65    if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
66        printf("[015] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
67
68    mysqli_stmt_close($stmt);
69
70    try {
71        mysqli_stmt_fetch($stmt);
72    } catch (Error $exception) {
73        echo $exception->getMessage() . "\n";
74    }
75
76    mysqli_close($link);
77
78    print "done!";
79?>
80--CLEAN--
81<?php
82    require_once("clean_table.inc");
83?>
84--EXPECTF--
85mysqli_stmt object is not fully initialized
86[014] [%d] Commands out of sync; you can't run this command now
87mysqli_stmt object is already closed
88done!
89