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