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