1--TEST--
2mysqli_character_set_name(), mysql_client_encoding() [alias]
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
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    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
15        printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
16            $host, $user, $db, $port, $socket);
17
18    if (!$res = mysqli_query($link, 'SELECT version() AS server_version'))
19        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20    $tmp = mysqli_fetch_assoc($res);
21    mysqli_free_result($res);
22    $version = explode('.', $tmp['server_version']);
23    if (empty($version))
24        printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
25
26    if ($version[0] <= 4 && $version[1] < 1)
27        printf("[007] Need MySQL Server 4.1+ for the test!\n");
28
29    if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
30            printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31    $tmp = mysqli_fetch_assoc($res);
32    mysqli_free_result($res);
33    if (!$tmp['charset'])
34        printf("[009] Cannot determine current character set and collation\n");
35
36    $charset = mysqli_character_set_name($link);
37    if ($tmp['charset'] !== $charset) {
38        if ($tmp['collation'] === $charset) {
39            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",
40            $tmp['collation'], $tmp['charset'], gettype($charset), $charset);
41        } else {
42            printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
43        }
44    }
45
46    $charset2 = mysqli_character_set_name($link);
47    if ($charset2 !== $charset) {
48        printf("[012] Alias mysqli_character_set_name returned %s/%s, expected  %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset);
49    }
50
51    mysqli_close($link);
52
53    try {
54        mysqli_character_set_name($link);
55    } catch (Error $exception) {
56        echo $exception->getMessage() . "\n";
57    }
58
59    print "done!";
60?>
61--EXPECT--
62mysqli object is already closed
63done!
64