1--TEST--
2mysqli_chararcter_set_name(), mysql_client_encoding() [alias]
3--SKIPIF--
4<?php
5	require_once('skipif.inc');
6	require_once('skipifemb.inc');
7	require_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 (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
18		printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
19			$host, $user, $db, $port, $socket);
20
21	if (!is_null($tmp = @$mysqli->character_set_name($link)))
22		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
23
24	if (!$res = $mysqli->query('SELECT version() AS server_version'))
25		printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
26	$tmp = $res->fetch_assoc();
27	$res->free_result();
28	$version = explode('.', $tmp['server_version']);
29	if (empty($version))
30		printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
31
32	if ($version[0] <= 4 && $version[1] < 1)
33		printf("[007] Need MySQL Server 4.1+ for the test!\n");
34
35	if (!$res = $mysqli->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
36		printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
37	$tmp = $res->fetch_assoc();
38	$res->free_result();
39	if (!$tmp['charset'])
40		printf("[009] Cannot determine current character set and collation\n");
41
42	$charset = $mysqli->character_set_name();
43	if ($tmp['charset'] !== $charset) {
44		if ($tmp['collation'] === $charset) {
45			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",
46				$tmp['collation'], $tmp['charset'], gettype($charset), $charset);
47		} else {
48			printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
49		}
50	}
51
52	$charset2 = $mysqli->character_set_name();
53	if ($charset2 !== $charset) {
54		printf("[012] Alias mysqli_character_set_name returned %s/%s, expected  %s/%s\n",
55			gettype($charset2), $charset2, gettype($charset), $charset);
56	}
57
58	$mysqli->close();
59
60	if (NULL !== ($tmp = @$mysqli->character_set_name()))
61		printf("[013] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
62
63	/* Make sure that the function alias exists */
64	if (!is_null($tmp = @$mysqli->character_set_name()))
65		printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
66
67	print "done!";
68?>
69--EXPECTF--
70done!
71