1--TEST--
2mysqli_stmt_get_result() - SHOW, DESCRIBE, EXPLAIN
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7
8if (!function_exists('mysqli_stmt_get_result'))
9    die('skip mysqli_stmt_get_result not available');
10?>
11--FILE--
12<?php
13    /*
14    NOTE: no datatype tests here! This is done by
15    mysqli_stmt_bind_result.phpt already. Restrict
16    this test case to the basics.
17    */
18    require('table.inc');
19
20    if (!$stmt = mysqli_stmt_init($link))
21        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    if (mysqli_query($link, 'PREPARE mystmt FROM "SHOW ENGINES"')) {
24        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
25
26        if (!$stmt->prepare('SHOW ENGINES') ||
27            !$stmt->execute())
28            printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
29
30        if (!$res = $stmt->get_result())
31            printf("[003] [%d] %s\n", $stmt->errno, $stmt->error);
32
33        $engines = mysqli_fetch_all($res, MYSQLI_NUM);
34        if	(empty($engines)) {
35            printf("[004] It is very unlikely that SHOW ENGINES returns no data, check manually\n");
36        } else {
37            $found = false;
38            foreach ($engines as $k => $engine)
39                foreach ($engine as $k => $v)
40                    if (stristr($v, 'MyISAM')) {
41                        $found = true;
42                        break;
43                    }
44            if (!$found)
45                printf("[005] It is very unlikely that SHOW ENGINES does not show MyISAM, check manually\n");
46        }
47        mysqli_free_result($res);
48    }
49
50    if (mysqli_query($link, 'PREPARE mystmt FROM "DESCRIBE test id"')) {
51        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
52
53        if (!$stmt->prepare('DESCRIBE test id') ||
54            !$stmt->execute())
55            printf("[006] [%d] %s\n", $stmt->errno, $stmt->error);
56
57        if (!$res = $stmt->get_result())
58            printf("[007] [%d] %s\n", $stmt->errno, $stmt->error);
59
60        $description = mysqli_fetch_assoc($res);
61        if ($description['Field'] != 'id') {
62            printf("[008] Returned data seems wrong, [%d] %s\n",
63                mysqli_errno($link), mysqli_error($link));
64            var_dump($description);
65        }
66        mysqli_free_result($res);
67    }
68
69    if (mysqli_query($link, 'PREPARE mystmt FROM "EXPLAIN SELECT id FROM test"')) {
70        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
71
72        if (!$stmt->prepare('EXPLAIN SELECT id FROM test') ||
73            !$stmt->execute())
74            printf("[009] [%d] %s\n", $stmt->errno, $stmt->error);
75
76        if (!$res = $stmt->get_result())
77            printf("[010] [%d] %s\n", $stmt->errno, $stmt->error);
78
79        $tmp = mysqli_fetch_assoc($res);
80        if (empty($tmp))
81            printf("[011] Empty EXPLAIN result set seems wrong, check manually, [%d] %s\n",
82                mysqli_errno($link), mysqli_error($link));
83        mysqli_free_result($res);
84    }
85    mysqli_close($link);
86
87    print "done!";
88?>
89--CLEAN--
90<?php
91    require_once("clean_table.inc");
92?>
93--EXPECT--
94done!
95