1--TEST--
2mysqli_real_escape_string() - gbk
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9
10if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
11	die(sprintf("skip Cannot connect to MySQL, [%d] %s\n",
12		mysqli_connect_errno(), mysqli_connect_error()));
13}
14if (!mysqli_set_charset($link, 'gbk'))
15	die(sprintf("skip Cannot set charset 'gbk'"));
16
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(3), PRIMARY
36KEY(id)) ENGINE=' . $engine . " DEFAULT CHARSET=gbk")) {
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, "gbk"));
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--EXPECTF--
71bool(true)
72bool(true)
73done!
74