1--TEST-- 2mysqli_real_connect() - persistent connections 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8require_once('connect.inc'); 9if (!$IS_MYSQLND) 10 die("skip mysqlnd only test"); 11?> 12--INI-- 13mysqli.allow_persistent=1 14mysqli.max_persistent=10 15--FILE-- 16<?php 17 require_once("connect.inc"); 18 $host = 'p:' . $host; 19 20 if (!$link = mysqli_init()) 21 printf("[002] mysqli_init() failed\n"); 22 23 if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) 24 printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 25 $host, $user, $db, $port, $socket); 26 27 mysqli_close($link); 28 if (!$link = mysqli_init()) 29 printf("[004] mysqli_init() failed\n"); 30 31 if (false !== ($tmp = mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))) 32 printf("[005] Expecting boolean/false got %s/%s. Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", gettype($tmp), $tmp, $host, $user . 'unknown_really', $db, $port, $socket); 33 34 // Run the following tests without an anoynmous MySQL user and use a password for the test user! 35 ini_set('mysqli.default_socket', $socket); 36 if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port)) { 37 printf("[006] Usage of mysqli.default_socket failed\n"); 38 } else { 39 mysqli_close($link); 40 if (!$link = mysqli_init()) 41 printf("[007] mysqli_init() failed\n"); 42 } 43 44 ini_set('mysqli.default_port', $port); 45 if (!mysqli_real_connect($link, $host, $user, $passwd, $db)) { 46 printf("[008] Usage of mysqli.default_port failed\n"); 47 } else { 48 mysqli_close($link); 49 if (!$link = mysqli_init()) 50 printf("[009] mysqli_init() failed\n"); 51 } 52 53 ini_set('mysqli.default_pw', $passwd); 54 if (!mysqli_real_connect($link, $host, $user)) { 55 printf("[010] Usage of mysqli.default_pw failed\n") ; 56 } else { 57 mysqli_close($link); 58 if (!$link = mysqli_init()) 59 printf("[011] mysqli_init() failed\n"); 60 } 61 62 ini_set('mysqli.default_user', $user); 63 if (!mysqli_real_connect($link, $host)) { 64 printf("[012] Usage of mysqli.default_user failed\n") ; 65 } else { 66 mysqli_close($link); 67 if (!$link = mysqli_init()) 68 printf("[011] mysqli_init() failed\n"); 69 } 70 71 ini_set('mysqli.default_host', $host); 72 if (!mysqli_real_connect($link)) { 73 printf("[014] Usage of mysqli.default_host failed\n") ; 74 } else { 75 mysqli_close($link); 76 if (!$link = mysqli_init()) 77 printf("[015] mysqli_init() failed\n"); 78 } 79 80 // CLIENT_MULTI_STATEMENTS - should be disabled silently 81 if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 65536)) 82 printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 83 84 if ($res = mysqli_query($link, "SELECT 1 AS a; SELECT 2 AS b")) { 85 printf("[017] Should have failed. CLIENT_MULTI_STATEMENT should have been disabled.\n"); 86 var_dump($res->num_rows); 87 mysqli_next_result($link); 88 $res = mysqli_store_result($link); 89 var_dump($res->num_rows); 90 } 91 92 93 mysqli_close($link); 94 if (!$link = mysqli_init()) 95 printf("[018] mysqli_init() failed\n"); 96 97 if (ini_get('open_basedir')) { 98 // CLIENT_LOCAL_FILES should be blocked - but how to test it ?! 99 100 if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 128)) 101 printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 102 103 $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mysqli_real_connect_phpt'; 104 if (!$fp = fopen($filename, 'w')) 105 printf("[020] Cannot open temporary file %s\n", $filename); 106 107 fwrite($fp, '100;z'); 108 fclose($fp); 109 110 // how do we test if gets forbidden because of a missing right or the flag, this test is partly bogus ? 111 if (mysqli_query($link, "LOAD DATA LOCAL INFILE '$filename' INTO TABLE test FIELDS TERMINATED BY ';'")) 112 printf("[021] LOAD DATA INFILE should have been forbidden!\n"); 113 114 unlink($filename); 115 } 116 117 mysqli_close($link); 118 119 if ($IS_MYSQLND) { 120 $link = mysqli_init(); 121 if (!@mysqli_real_connect($link)) { 122 printf("[022] Usage of mysqli.default_host=p:%s (persistent) failed\n", $host) ; 123 } else { 124 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host (persistent)' AS 'testing'")) 125 printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 126 $tmp = mysqli_fetch_assoc($res); 127 if ($tmp['testing'] !== 'mysqli.default_host (persistent)') { 128 printf("[024] Result looks strange - check manually, [%d] %s\n", 129 mysqli_errno($link), mysqli_error($link)); 130 var_dump($tmp); 131 } 132 mysqli_free_result($res); 133 mysqli_close($link); 134 } 135 136 ini_set('mysqli.default_host', 'p:'); 137 $link = mysqli_init(); 138 if (@mysqli_real_connect($link)) { 139 printf("[025] Usage of mysqli.default_host=p: did not fail\n") ; 140 mysqli_close($link); 141 } 142 } 143 144 if (NULL === ($tmp = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))) 145 printf("[026] Expecting not NULL, got %s/%s\n", gettype($tmp), $tmp); 146 147 print "done!"; 148?> 149--CLEAN-- 150<?php 151 require_once("clean_table.inc"); 152?> 153--EXPECTF-- 154Warning: mysqli_real_connect(): (%d/%d): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d 155done! 156