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