1--TEST-- 2mysqli_real_query() 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_real_query($link, 'THIS IS NOT SQL'))) 16 printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 17 18 if (false !== ($tmp = mysqli_real_query($link, "SELECT 'this is sql but with backslash g'\g"))) 19 printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 20 21 if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link))) 22 printf("[006] mysqli_errno()/mysqli_error should return some error\n"); 23 24 if (!mysqli_real_query($link, "SELECT 'this is sql but with semicolon' AS valid ; ")) 25 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 26 27 if (!is_object($res = mysqli_use_result($link))) 28 printf("[008] Expecting reseult object, got %s/%s [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link)); 29 30 var_dump(mysqli_fetch_assoc($res)); 31 mysqli_free_result($res); 32 33 if (false !== ($res = mysqli_real_query($link, "SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES"))) 34 printf("[008] Expecting boolean/false, got %s/%s, [%d] %s\n", gettype($res), $res, 35 mysqli_errno($link), mysqli_error($link)); 36 37 if (mysqli_get_server_version($link) > 50000) { 38 // let's try to play with stored procedures 39 mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p'); 40 if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; 41END;')) { 42 mysqli_real_query($link, 'CALL p(@version)'); 43 mysqli_real_query($link, 'SELECT @version AS p_version'); 44 $res = mysqli_store_result($link); 45 46 $tmp = mysqli_fetch_assoc($res); 47 if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || ('' == $tmp['p_version'])) { 48 printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 49 var_dump($tmp); 50 } 51 52 mysqli_free_result($res); 53 } else { 54 printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 55 } 56 mysqli_real_query($link, 'DROP FUNCTION IF EXISTS f'); 57 if (mysqli_real_query($link, 'CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN 58ver_param;')) { 59 mysqli_real_query($link, 'SELECT f(VERSION()) AS f_version'); 60 $res = mysqli_store_result($link); 61 62 $tmp = mysqli_fetch_assoc($res); 63 if (!is_array($tmp) || empty($tmp) || !isset($tmp['f_version']) || ('' == $tmp['f_version'])) { 64 printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 65 var_dump($tmp); 66 } 67 68 mysqli_free_result($res); 69 } else { 70 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 71 } 72 } 73 74 mysqli_close($link); 75 76 try { 77 mysqli_real_query($link, "SELECT id FROM test"); 78 } catch (Error $exception) { 79 echo $exception->getMessage() . "\n"; 80 } 81 82 print "done!"; 83?> 84--CLEAN-- 85<?php 86require_once("connect.inc"); 87if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 88 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 89 90if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 91 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 92 93@mysqli_query($link, "DROP PROCEDURE IF EXISTS p"); 94@mysqli_query($link, "DROP FUNCTION IF EXISTS f"); 95 96mysqli_close($link); 97?> 98--EXPECT-- 99array(1) { 100 ["valid"]=> 101 string(30) "this is sql but with semicolon" 102} 103mysqli object is already closed 104done! 105