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