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