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 $tmp = NULL; 14 $link = NULL; 15 16 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 17 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 18 $host, $user, $db, $port, $socket); 19 20 if (!$res = $mysqli->query('SELECT version() AS server_version')) 21 printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); 22 $tmp = $res->fetch_assoc(); 23 $res->free_result(); 24 $version = explode('.', $tmp['server_version']); 25 if (empty($version)) 26 printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n"); 27 28 if ($version[0] <= 4 && $version[1] < 1) 29 printf("[007] Need MySQL Server 4.1+ for the test!\n"); 30 31 if (!$res = $mysqli->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation')) 32 printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); 33 $tmp = $res->fetch_assoc(); 34 $res->free_result(); 35 if (!$tmp['charset']) 36 printf("[009] Cannot determine current character set and collation\n"); 37 38 $charset = $mysqli->character_set_name(); 39 if ($tmp['charset'] !== $charset) { 40 if ($tmp['collation'] === $charset) { 41 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", 42 $tmp['collation'], $tmp['charset'], gettype($charset), $charset); 43 } else { 44 printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset); 45 } 46 } 47 48 $charset2 = $mysqli->character_set_name(); 49 if ($charset2 !== $charset) { 50 printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", 51 gettype($charset2), $charset2, gettype($charset), $charset); 52 } 53 54 $mysqli->close(); 55 56 try { 57 $mysqli->character_set_name(); 58 } catch (Error $exception) { 59 echo $exception->getMessage() . "\n"; 60 } 61 62 try { 63 $mysqli->character_set_name(); 64 } catch (Error $exception) { 65 echo $exception->getMessage() . "\n"; 66 } 67 68 print "done!"; 69?> 70--EXPECT-- 71my_mysqli object is already closed 72my_mysqli object is already closed 73done! 74