1--TEST-- 2new mysqli() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require_once("connect.inc"); 11 12 $tmp = NULL; 13 $link = NULL; 14 15 if ($socket != "") 16 /* mysqli.default_socket requires non-empty string */ 17 ini_set('mysqli.default_socket', 'socket'); 18 19 ini_set('mysqli.default_port', 9999); 20 ini_set('mysqli.default_pw', 'password'); 21 ini_set('mysqli.default_user', 'user'); 22 ini_set('mysqli.default_host', 'host'); 23 24 mysqli_report(MYSQLI_REPORT_OFF); 25 mysqli_report(MYSQLI_REPORT_STRICT); 26 27 if ($socket != "") { 28 ini_set('mysqli.default_socket', $socket); 29 try { 30 $mysqli = mysqli_init(); 31 $mysqli->real_connect($host, $user, $passwd, $db, $port); 32 33 if (!$res = $mysqli->query("SELECT 'mysqli.default_socket' AS testing")) 34 printf("[001] [%d] %s\n", $mysqli->errno, $mysqli->error); 35 $tmp = $res->fetch_assoc(); 36 $res->free_result(); 37 38 if (!isset($tmp['testing']) || $tmp['testing'] != 'mysqli.default_socket') { 39 printf("[002] mysqli.default_socket not properly set?\n"); 40 var_dump($tmp); 41 } 42 43 $mysqli->close(); 44 45 } catch (mysqli_sql_exception $e) { 46 printf("%s\n", $e->getMessage()); 47 printf("[002] Usage of mysqli.default_socket failed\n"); 48 } 49 } 50 51 ini_set('mysqli.default_port', $port); 52 try { 53 $mysqli = mysqli_init(); 54 $mysqli->real_connect($host, $user, $passwd, $db); 55 56 if (!$res = $mysqli->query("SELECT 'mysqli.default_port' AS testing")) 57 printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); 58 var_dump($res->fetch_assoc()); 59 $res->free_result(); 60 61 $mysqli->close(); 62 63 } catch (mysqli_sql_exception $e) { 64 printf("%s\n", $e->getMessage()); 65 printf("[004] Usage of mysqli.default_port failed\n"); 66 } 67 68 ini_set('mysqli.default_pw', $passwd); 69 try { 70 $mysqli = mysqli_init(); 71 $mysqli->real_connect($host, $user); 72 $mysqli->select_db($db); 73 74 if (!$res = $mysqli->query("SELECT 'mysqli.default_pw' AS testing")) 75 printf("[005] [%d] %s\n", $mysqli->errno, $mysqli->error); 76 var_dump($res->fetch_assoc()); 77 $res->free_result(); 78 79 $mysqli->close(); 80 81 } catch (mysqli_sql_exception $e) { 82 printf("%s\n", $e->getMessage()); 83 printf("[006] Usage of mysqli.default_pw failed\n"); 84 } 85 86 ini_set('mysqli.default_user', $user); 87 try { 88 $mysqli = mysqli_init(); 89 $mysqli->real_connect($host); 90 $mysqli->select_db($db); 91 92 if (!$res = $mysqli->query("SELECT 'mysqli.default_user' AS testing")) 93 printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error); 94 var_dump($res->fetch_assoc()); 95 $res->free_result(); 96 97 $mysqli->close(); 98 99 } catch (mysqli_sql_exception $e) { 100 printf("%s\n", $e->getMessage()); 101 printf("[008] Usage of mysqli.default_user failed\n"); 102 } 103 104 ini_set('mysqli.default_host', $host); 105 try { 106 $mysqli = mysqli_init(); 107 $mysqli->real_connect(); 108 $mysqli->select_db($db); 109 110 if (!$res = $mysqli->query("SELECT 1")) 111 printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error); 112 $res->free_result(); 113 114 if (!$res = $mysqli->query("SELECT SUBSTRING_INDEX(USER(),'@',1) AS username")) 115 printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error); 116 117 $tmp = $res->fetch_assoc(); 118 $res->free_result(); 119 if ($tmp['username'] !== $user) 120 printf("[011] Expecting string/%s, got %s/%s\n", $user, gettype($tmp['username']), $tmp['username']); 121 122 $mysqli->close(); 123 124 } catch (mysqli_sql_exception $e) { 125 printf("%s\n", $e->getMessage()); 126 printf("[012] Usage of mysqli.default_host failed\n"); 127 } 128 129 try { 130 $link = mysqli_connect($host, $user, $passwd, null, ini_get('mysqli.default_port')); 131 mysqli_select_db($link, $db); 132 if (!$res = mysqli_query($link, "SELECT 'have been set' AS all_defaults")) 133 printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 134 var_dump(mysqli_fetch_assoc($res)); 135 mysqli_free_result($res); 136 mysqli_close($link); 137 } catch (mysqli_sql_exception $e) { 138 printf("%s\n", $e->getMessage()); 139 printf("[014] Usage of mysqli_connect() has failed\n"); 140 } 141 142 try { 143 $link = mysqli_connect($host, $user, $passwd, null); 144 mysqli_select_db($link, $db); 145 if (!$res = mysqli_query($link, "SELECT 'have been set' AS all_defaults")) 146 printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 147 var_dump(mysqli_fetch_assoc($res)); 148 mysqli_free_result($res); 149 mysqli_close($link); 150 } catch (mysqli_sql_exception $e) { 151 printf("%s\n", $e->getMessage()); 152 printf("[016] Usage of mysqli_connect() has failed\n"); 153 } 154 155 156 print "done!"; 157?> 158--EXPECT-- 159array(1) { 160 ["testing"]=> 161 string(19) "mysqli.default_port" 162} 163array(1) { 164 ["testing"]=> 165 string(17) "mysqli.default_pw" 166} 167array(1) { 168 ["testing"]=> 169 string(19) "mysqli.default_user" 170} 171array(1) { 172 ["all_defaults"]=> 173 string(13) "have been set" 174} 175array(1) { 176 ["all_defaults"]=> 177 string(13) "have been set" 178} 179done! 180