1--TEST-- 2mysqli->change_user() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8 9require_once 'table.inc'; 10 11if (mysqli_get_server_version($link) >= 50600) 12 die("SKIP For MySQL < 5.6.0"); 13?> 14--FILE-- 15<?php 16 require_once "connect.inc"; 17 18 $link = NULL; 19 $tmp = NULL; 20 21 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 22 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 23 $host, $user, $db, $port, $socket); 24 25 if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db))) 26 printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 27 28 if (false !== ($tmp = $mysqli->change_user($user, $passwd . '_unknown_really', $db))) 29 printf("[007] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 30 31 if (false !== ($tmp = $mysqli->change_user($user, $passwd, $db . '_unknown_really'))) 32 printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 33 34 // Reconnect because after 3 failed change_user attempts, the server blocks you off. 35 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 36 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 37 $host, $user, $db, $port, $socket); 38 39 if (!$mysqli->query('SET @mysqli_change_user_test_var=1')) 40 printf("[009] Failed to set test variable: [%d] %s\n", $mysqli->errno, $mysqli->error); 41 42 if (!$res = $mysqli->query('SELECT @mysqli_change_user_test_var AS test_var')) 43 printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error); 44 $tmp = $res->fetch_assoc(); 45 $res->free_result(); 46 if (1 != $tmp['test_var']) 47 printf("[011] Cannot set test variable\n"); 48 49 if (true !== ($tmp = $mysqli->change_user($user, $passwd, $db))) 50 printf("[012] Expecting true, got %s/%s\n", gettype($tmp), $tmp); 51 52 if (!$res = $mysqli->query('SELECT database() AS dbname, user() AS user')) 53 printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error); 54 $tmp = $res->fetch_assoc(); 55 $res->free_result(); 56 57 if (substr($tmp['user'], 0, strlen($user)) !== $user) 58 printf("[014] Expecting user %s, got user() %s\n", $user, $tmp['user']); 59 if ($tmp['dbname'] != $db) 60 printf("[015] Expecting database %s, got database() %s\n", $db, $tmp['dbname']); 61 62 if (!$res = $mysqli->query('SELECT @mysqli_change_user_test_var AS test_var')) 63 printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error); 64 $tmp = $res->fetch_assoc(); 65 $res->free_result(); 66 if (NULL !== $tmp['test_var']) 67 printf("[017] Test variable is still set!\n"); 68 69 $mysqli->close(); 70 71 if (false !== ($tmp = @$mysqli->change_user($user, $passwd, $db))) 72 printf("[018] Expecting false, got %s/%s\n", gettype($tmp), $tmp); 73 74 print "done!"; 75?> 76--EXPECT-- 77done! 78