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