1--TEST--
2mysqli_prepare()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    require('table.inc');
14
15    if (false !== ($tmp = @mysqli_prepare($link, false)))
16        printf("[003] Expecting boolean/false, got %s\n", gettype($tmp));
17
18    if (!$res = mysqli_query($link, "SELECT id, label FROM test", MYSQLI_USE_RESULT))
19        printf("[004] [%d] %s, next test will fail\n", mysqli_errno($link), mysqli_error($link));
20
21    if (false !== ($tmp = mysqli_prepare($link, 'SELECT id FROM test WHERE id > ?')))
22        printf("[005] Expecting boolean/false, got %s, [%d] %s\n", gettype($tmp), mysqli_errno($link), mysqli_error($link));
23
24    mysqli_free_result($res);
25
26    if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id FROM test'))) || !mysqli_stmt_execute($stmt))
27        printf("[006][%d] %s\n", mysqli_errno($link), mysqli_error($link));
28    mysqli_stmt_close($stmt);
29
30
31    if (!mysqli_query($link, "DROP TABLE IF EXISTS test2"))
32        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
33
34    if (!is_object(($stmt = mysqli_prepare($link, 'CREATE TABLE test2(id INT) ENGINE =' . $engine))) || !mysqli_stmt_execute($stmt))
35        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
36    mysqli_stmt_close($stmt);
37
38
39    if (!is_object(($stmt = mysqli_prepare($link, 'INSERT INTO test2(id) VALUES(?)'))))
40        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41
42    $id = 1;
43    if (!mysqli_stmt_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt))
44        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
45    mysqli_stmt_close($stmt);
46
47    if (!is_object(($stmt = mysqli_prepare($link, 'REPLACE INTO test2(id) VALUES (?)'))))
48        printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
49
50    $id = 2;
51    if (!mysqli_stmt_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt))
52        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53    mysqli_stmt_close($stmt);
54
55    if (!is_object(($stmt = mysqli_prepare($link, 'UPDATE test2 SET id = ? WHERE id = ?'))))
56        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58    $id = 3;
59    $where = 2;
60    if (!mysqli_stmt_bind_param($stmt, 'ii', $id, $where) || !mysqli_stmt_execute($stmt))
61        printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62    mysqli_stmt_close($stmt);
63
64    if (!is_object(($stmt = mysqli_prepare($link, 'DELETE FROM test2 WHERE id = ?'))))
65        printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
66
67    $where = 3;
68    if (!mysqli_stmt_bind_param($stmt, 'i', $where) || !mysqli_stmt_execute($stmt))
69        printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
70    mysqli_stmt_close($stmt);
71
72    if (!is_object(($stmt = mysqli_prepare($link, 'SET @testvar = ?'))))
73        printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
74
75    $testvar = 'testvar';
76    if (!mysqli_stmt_bind_param($stmt, 's', $testvar) || !mysqli_stmt_execute($stmt))
77        printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
78    mysqli_stmt_close($stmt);
79
80    if (!is_object(($stmt = mysqli_prepare($link, "DO GET_LOCK('testlock', 1)"))))
81        printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
82    mysqli_stmt_close($stmt);
83
84    if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id, @testvar FROM test2'))))
85        printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
86
87    $id = $testvar = null;
88    if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_bind_result($stmt, $id, $testvar))
89        printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
90    while (mysqli_stmt_fetch($stmt)) {
91        if (('testvar' !== $testvar) || (1 !== $id))
92            printf("[022] Expecting 'testvar'/1, got %s/%s. [%d] %s\n",
93                $testvar, $id, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
94    }
95
96    var_dump(mysqli_stmt_prepare($stmt, 'SELECT 1; SELECT 2'));
97
98    mysqli_stmt_close($stmt);
99    mysqli_close($link);
100
101    print "done!";
102?>
103--CLEAN--
104<?php
105require_once("connect.inc");
106if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
107   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
108
109if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
110    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
111
112if (!mysqli_query($link, "DROP TABLE IF EXISTS test2"))
113    printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
114
115mysqli_close($link);
116?>
117--EXPECT--
118bool(false)
119done!
120