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