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