1--TEST-- 2mysqli_driver class 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require("table.inc"); 11 12 if (!is_object($driver = new mysqli_driver())) 13 printf("[001] Failed to create mysqli_driver object\n"); 14 15 $client_info = mysqli_get_client_info(); 16 if (($tmp = $driver->client_info) !== $client_info) 17 printf("[002] Expecting %s/%s, got %s/%s\n", 18 gettype($client_info), $client_info, 19 gettype($tmp), $tmp); 20 21 $client_version = mysqli_get_client_version(); 22 if (($tmp = $driver->client_version) !== $client_version) 23 printf("[003] Expecting %s/%s, got %s/%s\n", 24 gettype($client_version), $client_version, 25 gettype($tmp), $tmp); 26 27 if (!is_int($tmp = $driver->driver_version) || (0 == $tmp)) 28 printf("[004] Expecting int/any, got %s/%s\n", 29 gettype($tmp), $tmp); 30 31 32 $all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT, 33 MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF); 34 $report_mode = $driver->report_mode; 35 if (!is_int($report_mode)) 36 printf("[005] Expecting int/any, got %s/%s\n", 37 gettype($report_mode), $report_mode); 38 39 if (!in_array($report_mode, $all_modes)) 40 printf("[006] Illegal report mode returned? Got %s, expected %s\n", 41 $report_mode, implode(', ', $all_modes)); 42 43 $driver->report_mode = MYSQLI_REPORT_STRICT; 44 $ok = false; 45 try { 46 47 if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) 48 printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", 49 $host, $user . 'unknown_really', $db, $port, $socket); 50 mysqli_close($link); 51 52 } catch (mysqli_sql_exception $e) { 53 $ok = true; 54 if ('' == $e->getMessage()) 55 printf("[008] getMessage() has returned an empty string.\n"); 56 if ('' == $e->getCode()) 57 printf("[009] getCode() has returned an empty string.\n"); 58 if ('' == $e->getFile()) 59 printf("[010] getFile() has returned an empty string.\n"); 60 if ('' == $e->getLine()) 61 printf("[011] getLine() has returned an empty string.\n"); 62 $tmp = $e->getTrace(); 63 if (empty($tmp)) 64 printf("[012] getTrace() has returned an empty array.\n"); 65 if ('' == $e->getTraceAsString()) 66 printf("[013] getTraceAsString() has returned an empty string.\n"); 67 if ('' == $e->__toString()) 68 printf("[014] __toString() has returned an empty string.\n"); 69 70 } 71 if (!$ok) 72 printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n"); 73 74 75 $driver->report_mode = MYSQLI_REPORT_OFF; 76 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 77 printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 78 mysqli_query($link, "NO_SQL"); 79 mysqli_close($link); 80 81 $driver->report_mode = MYSQLI_REPORT_ERROR; 82 83 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 84 printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 85 mysqli_query($link, "NO_SQL"); 86 mysqli_close($link); 87 88 if (MYSQLI_REPORT_ERROR !== $driver->report_mode) 89 printf("[018] Error mode should be different\n"); 90 91 /* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */ 92 93 $driver->report_mode = $report_mode; 94 95 $reconnect = $driver->reconnect; 96 if (!is_bool($reconnect)) 97 printf("[019] Expecting boolean/any, got %s/%s\n", 98 gettype($reconnect), $reconnect); 99 100 /* pointless, but I need more documentation */ 101 $driver->reconnect = true; 102 $driver->reconnect = false; 103 $driver->reconnect = $reconnect; 104 105 print "done!"; 106?> 107--EXPECTF-- 108Warning: 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 'NO_SQL' at line 1 in %s on line %d 109done! 110