1--TEST--
2mysqli_chararcter_set_name(), mysql_client_encoding() [alias]
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
12	require_once("connect.inc");
13
14	$tmp    = NULL;
15	$link   = NULL;
16
17	if (!is_null($tmp = @mysqli_character_set_name()))
18		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
19
20	if (!is_null($tmp = @mysqli_character_set_name($link)))
21		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
22
23	if (!is_null($tmp = @mysqli_character_set_name($link, $link, $link)))
24		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
25
26	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
27		printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
28			$host, $user, $db, $port, $socket);
29
30	if (!$res = mysqli_query($link, 'SELECT version() AS server_version'))
31		printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
32	$tmp = mysqli_fetch_assoc($res);
33	mysqli_free_result($res);
34	$version = explode('.', $tmp['server_version']);
35	if (empty($version))
36		printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
37
38	if ($version[0] <= 4 && $version[1] < 1)
39		printf("[007] Need MySQL Server 4.1+ for the test!\n");
40
41	if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
42			printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43	$tmp = mysqli_fetch_assoc($res);
44	mysqli_free_result($res);
45	if (!$tmp['charset'])
46		printf("[009] Cannot determine current character set and collation\n");
47
48	$charset = mysqli_character_set_name($link);
49	if ($tmp['charset'] !== $charset) {
50		if ($tmp['collation'] === $charset) {
51			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",
52			$tmp['collation'], $tmp['charset'], gettype($charset), $charset);
53		} else {
54			printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
55		}
56	}
57
58	$charset2 = mysqli_character_set_name($link);
59	if ($charset2 !== $charset) {
60		printf("[012] Alias mysqli_character_set_name returned %s/%s, expected  %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset);
61	}
62
63	mysqli_close($link);
64
65	if (NULL !== ($tmp = @mysqli_character_set_name($link)))
66		printf("[013] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
67
68	/* Make sure that the function alias exists */
69	if (!is_null($tmp = @mysqli_character_set_name()))
70		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
71
72	print "done!";
73?>
74--EXPECTF--
75done!