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