1--TEST--
2mysqli_real_escape_string() - gbk
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once __DIR__ . '/test_setup/test_helpers.inc';
8$link = mysqli_connect_or_skip();
9if (!mysqli_set_charset($link, 'gbk'))
10    die(sprintf("skip Cannot set charset 'gbk'"));
11?>
12--FILE--
13<?php
14
15    require_once 'connect.inc';
16    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
17{
18        printf("[001] Cannot connect to the server using host=%s, user=%s,
19passwd=***, dbname=%s, port=%s, socket=%s - [%d] %s\n", $host, $user, $db,
20$port, $socket, mysqli_connect_errno(), mysqli_connect_error());
21    }
22
23    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
24        printf("Failed to drop old test table: [%d] %s\n", mysqli_errno($link),
25mysqli_error($link));
26    }
27
28    if (!mysqli_query($link, 'CREATE TABLE test(id INT, label CHAR(3), PRIMARY
29KEY(id)) ENGINE=' . $engine . " DEFAULT CHARSET=gbk")) {
30        printf("Failed to create test table: [%d] %s\n", mysqli_errno($link),
31mysqli_error($link));
32    }
33
34    var_dump(mysqli_set_charset($link, "gbk"));
35
36    if ('�İ汾\\\\�İ汾' !== ($tmp = mysqli_real_escape_string($link, '�İ汾\\�İ汾')))
37        printf("[004] Expecting \\\\, got %s\n", $tmp);
38
39    if ('�İ汾\"�İ汾' !== ($tmp = mysqli_real_escape_string($link, '�İ汾"�İ汾')))
40        printf("[005] Expecting \", got %s\n", $tmp);
41
42    if ("�İ汾\'�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾'�İ汾")))
43        printf("[006] Expecting ', got %s\n", $tmp);
44
45    if ("�İ汾\\n�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾\n�İ汾")))
46        printf("[007] Expecting \\n, got %s\n", $tmp);
47
48    if ("�İ汾\\r�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾\r�İ汾")))
49        printf("[008] Expecting \\r, got %s\n", $tmp);
50
51    if ("�İ汾\\0�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾" . chr(0) . "�İ汾")))
52        printf("[009] Expecting %s, got %s\n", "�İ汾\\0�İ汾", $tmp);
53
54    var_dump(mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, '��')"));
55
56    mysqli_close($link);
57    print "done!";
58?>
59--CLEAN--
60<?php
61    require_once 'clean_table.inc';
62?>
63--EXPECT--
64bool(true)
65bool(true)
66done!
67