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