1--TEST-- 2mysqli_character_set_name(), mysql_client_encoding() [alias] 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 /* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */ 11 require_once("connect.inc"); 12 13 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 14 printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 15 $host, $user, $db, $port, $socket); 16 17 if (!$res = mysqli_query($link, 'SELECT version() AS server_version')) 18 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 19 $tmp = mysqli_fetch_assoc($res); 20 mysqli_free_result($res); 21 $version = explode('.', $tmp['server_version']); 22 if (empty($version)) 23 printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n"); 24 25 if ($version[0] <= 4 && $version[1] < 1) 26 printf("[007] Need MySQL Server 4.1+ for the test!\n"); 27 28 if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation')) 29 printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 30 $tmp = mysqli_fetch_assoc($res); 31 mysqli_free_result($res); 32 if (!$tmp['charset']) 33 printf("[009] Cannot determine current character set and collation\n"); 34 35 $charset = mysqli_character_set_name($link); 36 if ($tmp['charset'] !== $charset) { 37 if ($tmp['collation'] === $charset) { 38 printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n", 39 $tmp['collation'], $tmp['charset'], gettype($charset), $charset); 40 } else { 41 printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset); 42 } 43 } 44 45 $charset2 = mysqli_character_set_name($link); 46 if ($charset2 !== $charset) { 47 printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset); 48 } 49 50 mysqli_close($link); 51 52 try { 53 mysqli_character_set_name($link); 54 } catch (Error $exception) { 55 echo $exception->getMessage() . "\n"; 56 } 57 58 print "done!"; 59?> 60--EXPECT-- 61mysqli object is already closed 62done! 63