1--TEST-- 2mysqli_report(), MySQL < 5.6 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7 8if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 9 die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 10 $host, $user, $db, $port, $socket)); 11 12if (mysqli_get_server_version($link) >= 50600) 13 die("SKIP For MySQL < 5.6.0"); 14?> 15--FILE-- 16<?php 17 require_once("connect.inc"); 18 19 $tmp = NULL; 20 $link = NULL; 21 22 if (true !== ($tmp = mysqli_report(-1))) 23 printf("[002] Expecting boolean/true even for invalid flags, got %s/%s\n", gettype($tmp), $tmp); 24 25 if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ERROR))) 26 printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 27 28 if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_STRICT))) 29 printf("[004] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 30 31 if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_INDEX))) 32 printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 33 34 if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ALL))) 35 printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 36 37 if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_OFF))) 38 printf("[008] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 39 40 require('table.inc'); 41 42 /* 43 Internal macro MYSQL_REPORT_ERROR 44 */ 45 mysqli_report(MYSQLI_REPORT_ERROR); 46 47 mysqli_multi_query($link, "BAR; FOO;"); 48 mysqli_query($link, "FOO"); 49 mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db); 50 try { 51 mysqli_kill($link, -1); 52 } catch (\ValueError $e) { 53 echo $e->getMessage() . \PHP_EOL; 54 } 55 56 // mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it 57 mysqli_real_query($link, "FOO"); 58 if (@mysqli_select_db($link, "Oh lord, let this be an unknown database name")) 59 printf("[009] select_db should have failed\n"); 60 // mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it 61 62 63 // Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would 64 // not have been set. If that would be the case, the test would be broken. 65 mysqli_report(MYSQLI_REPORT_OFF); 66 67 mysqli_multi_query($link, "BAR; FOO;"); 68 mysqli_query($link, "FOO"); 69 mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db); 70 try { 71 mysqli_kill($link, -1); 72 } catch (\ValueError $e) { 73 echo $e->getMessage() . \PHP_EOL; 74 } 75 mysqli_real_query($link, "FOO"); 76 mysqli_select_db($link, "Oh lord, let this be an unknown database name"); 77 78 mysqli_report(MYSQLI_REPORT_OFF); 79 mysqli_report(MYSQLI_REPORT_STRICT); 80 81 try { 82 83 if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) 84 printf("[010] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", 85 $host, $user . 'unknown_really', $db, $port, $socket); 86 mysqli_close($link); 87 88 } catch (mysqli_sql_exception $e) { 89 printf("[011] %s\n", $e->getMessage()); 90 } 91 92 try { 93 if (!$link = mysqli_init()) 94 printf("[012] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 95 96 if ($link = my_mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) 97 printf("[013] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", 98 $host, $user . 'unknown_really', $db, $port, $socket); 99 mysqli_close($link); 100 } catch (mysqli_sql_exception $e) { 101 printf("[014] %s\n", $e->getMessage()); 102 } 103 104 print "done!"; 105?> 106--CLEAN-- 107<?php 108 require_once("clean_table.inc"); 109?> 110--EXPECTF-- 111Warning: mysqli_multi_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'BAR; FOO' at line 1 in %s on line %d 112 113Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d 114 115Warning: mysqli_change_user(): (%d/%d): Access denied for user '%s'@'%s' (using password: %s) in %s on line %d 116mysqli_kill(): Argument #2 ($process_id) must be greater than 0 117 118Warning: mysqli_real_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d 119mysqli_kill(): Argument #2 ($process_id) must be greater than 0 120[011] Access denied for user '%s'@'%s' (using password: YES) 121[014] Access denied for user '%s'@'%s' (using password: YES) 122done! 123