1--TEST--
2mysqli_stmt_get_result() - SHOW, DESCRIBE, EXPLAIN
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("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20
21    if (mysqli_query($link, 'PREPARE mystmt FROM "SHOW ENGINES"')) {
22        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
23
24        if (!$stmt->prepare('SHOW ENGINES') ||
25            !$stmt->execute())
26            printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
27
28        if (!$res = $stmt->get_result())
29            printf("[003] [%d] %s\n", $stmt->errno, $stmt->error);
30
31        $engines = mysqli_fetch_all($res, MYSQLI_NUM);
32        if	(empty($engines)) {
33            printf("[004] It is very unlikely that SHOW ENGINES returns no data, check manually\n");
34        } else {
35            $found = false;
36            foreach ($engines as $engine) {
37                if (stristr($engine[0], 'MyISAM')) {
38                    $found = true;
39                    break;
40                }
41            }
42            if (!$found)
43                printf("[005] It is very unlikely that SHOW ENGINES does not show MyISAM, check manually\n");
44        }
45        mysqli_free_result($res);
46    }
47
48    if (mysqli_query($link, 'PREPARE mystmt FROM "DESCRIBE test id"')) {
49        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
50
51        if (!$stmt->prepare('DESCRIBE test id') ||
52            !$stmt->execute())
53            printf("[006] [%d] %s\n", $stmt->errno, $stmt->error);
54
55        if (!$res = $stmt->get_result())
56            printf("[007] [%d] %s\n", $stmt->errno, $stmt->error);
57
58        $description = mysqli_fetch_assoc($res);
59        if ($description['Field'] != 'id') {
60            printf("[008] Returned data seems wrong, [%d] %s\n",
61                mysqli_errno($link), mysqli_error($link));
62            var_dump($description);
63        }
64        mysqli_free_result($res);
65    }
66
67    if (mysqli_query($link, 'PREPARE mystmt FROM "EXPLAIN SELECT id FROM test"')) {
68        mysqli_query($link, 'DEALLOCATE PREPARE mystmt');
69
70        if (!$stmt->prepare('EXPLAIN SELECT id FROM test') ||
71            !$stmt->execute())
72            printf("[009] [%d] %s\n", $stmt->errno, $stmt->error);
73
74        if (!$res = $stmt->get_result())
75            printf("[010] [%d] %s\n", $stmt->errno, $stmt->error);
76
77        $tmp = mysqli_fetch_assoc($res);
78        if (empty($tmp))
79            printf("[011] Empty EXPLAIN result set seems wrong, check manually, [%d] %s\n",
80                mysqli_errno($link), mysqli_error($link));
81        mysqli_free_result($res);
82    }
83    mysqli_close($link);
84
85    print "done!";
86?>
87--CLEAN--
88<?php
89    require_once 'clean_table.inc';
90?>
91--EXPECT--
92done!
93