xref: /php-src/ext/mysqli/tests/065.phpt (revision aab36a77)
1--TEST--
2set character set
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12
13    $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
14
15    if (!mysqli_query($mysql, "SET sql_mode=''"))
16        printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));
17
18    $esc_str = chr(0xbf) . chr(0x5c);
19    $len = $charset = array();
20    $tmp = null;
21
22    if ($mysql->set_charset("latin1")) {
23        /* 5C should be escaped */
24        if (3 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
25            printf("[003] Expecting 3/int got %s/%s\n", gettype($tmp), $tmp);
26
27        if ('latin1' !== ($tmp = $mysql->character_set_name()))
28            printf("[004] Expecting latin1/string got %s/%s\n", gettype($tmp), $tmp);
29    }
30
31    if ($res = $mysql->query("SHOW CHARACTER SET LIKE 'gbk'")) {
32        $res->free_result();
33        if ($mysql->set_charset("gbk")) {
34            /* nothing should be escaped, it's a valid gbk character */
35
36            if (2 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
37                    printf("[005] Expecting 2/int got %s/%s\n", gettype($tmp), $tmp);
38
39            if ('gbk' !== ($tmp = $mysql->character_set_name()))
40                    printf("[005] Expecting gbk/string got %s/%s\n", gettype($tmp), $tmp);
41        }
42    }
43    $mysql->close();
44
45    print "done!";
46?>
47--EXPECT--
48done!
49