1--TEST--
2mysql_client_encoding()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10include_once "connect.inc";
11
12$tmp    = NULL;
13$link   = NULL;
14
15if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
16	printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
17		$host, $user, $db, $port, $socket);
18
19$default_link_enc = mysql_client_encoding();
20$link_enc = mysql_client_encoding($link);
21
22if ($default_link_enc !== $link_enc)
23	printf("[003] %s != %s, [%d] %s\n", $default_link_enc, $link_enc, mysql_errno($link), mysql_error($link));
24
25if (!$res = mysql_query('SELECT version() AS server_version', $link))
26	printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link));
27$tmp = mysql_fetch_assoc($res);
28mysql_free_result($res);
29$version = explode('.', $tmp['server_version']);
30if (empty($version))
31	printf("[005] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
32
33if ($version[0] <= 4 && $version[1] < 1)
34	printf("[006] Need MySQL Server 4.1+ for the test!\n");
35
36if (!$res = mysql_query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation', $link))
37	printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
38$tmp = mysql_fetch_assoc($res);
39mysql_free_result($res);
40if (!$tmp['charset'])
41	printf("[008] Cannot determine current character set and collation\n");
42
43if ($link_enc !== $tmp['charset']) {
44	if ($link_enc === $tmp['collation']) {
45		printf("[009] Known bug, collation instead of chatset returned, http://bugs.mysql.com/bug.php?id=7923\n");
46	} else {
47		printf("[009] Check manually, watch out for unicode and others\n");
48		var_dump($link_enc);
49		var_dump($tmp);
50	}
51}
52
53if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && function_exists('is_unicode')) {
54// unicode mode
55	if (!is_unicode($default_link_enc) || !is_unicode($link_enc)) {
56		printf("[010] No unicode returned!\n");
57		var_dump($default_link_enc);
58		var_dump($link_enc);
59	}
60}
61
62mysql_close($link);
63
64if (false !== ($tmp = @mysql_client_encoding($link)))
65	printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
66
67print "done!";
68?>
69--EXPECTF--
70Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
71done!
72