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