1--TEST--
2mysqli_real_escape_string()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	$tmp	= NULL;
14	$link	= NULL;
15
16	if (NULL !== ($tmp = @mysqli_real_escape_string()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (NULL !== ($tmp = @mysqli_real_escape_string($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	if (NULL !== ($tmp =@mysqli_real_escape_string($link, "фуу", "бар")))
25		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
26
27	if ('фу\\\\бар' !== ($tmp = mysqli_real_escape_string($link, 'фу\\бар')))
28		printf("[004] Expecting фу\\\\бар, got %s\n", $tmp);
29
30	if ('бар\"фус' !== ($tmp = mysqli_real_escape_string($link, 'бар"фус')))
31		printf("[005] Expecting бар\"фус, got %s\n", $tmp);
32
33	if ("лала\'лали" !== ($tmp = mysqli_real_escape_string($link, "лала'лали")))
34		printf("[006] Expecting лала'лали, got %s\n", $tmp);
35
36	if ("абра\\nкадабра" !== ($tmp = mysqli_real_escape_string($link, "абра\nкадабра")))
37		printf("[007] Expecting абра\\nкадабра, got %s\n", $tmp);
38
39	if ("манда\\rин" !== ($tmp = mysqli_real_escape_string($link, "манда\rин")))
40		printf("[008] Expecting \\r, got %s\n", $tmp);
41
42	if ("иху\\0аху" !== ($tmp = mysqli_real_escape_string($link, "иху" . chr(0) . "аху")))
43		printf("[009] Expecting %s, got %s\n", "иху\\0аху", $tmp);
44
45	if (($exp='абра\\\\ка\"да\\'."'".'бра\Zсим\\nсала\\rби\\0м') !==
46		($tmp = mysqli_real_escape_string($link, "абра\\ка\"да'бра\032сим\nсала\rби" . chr(0) . "м")))
47	{
48		printf("[010] Expecting %s, got %s\n", $exp, $tmp, var_dump($exp, $tmp));
49	}
50
51	if ('富\\\\酒吧' !== ($tmp = mysqli_real_escape_string($link, '富\\酒吧')))
52		printf("[011] Expecting 富\\\\酒吧, got %s\n", $tmp);
53
54	if ('酒吧\"小题大做' !== ($tmp = mysqli_real_escape_string($link, '酒吧"小题大做')))
55		printf("[012] Expecting 酒吧\"小题大做, got %s\n", $tmp);
56
57	if ("拉拉\'西雅图" !== ($tmp = mysqli_real_escape_string($link, "拉拉'西雅图")))
58		printf("[013] Expecting 拉拉'西雅图, got %s\n", $tmp);
59
60	if ("阿卜拉\\n轻" !== ($tmp = mysqli_real_escape_string($link, "阿卜拉\n轻")))
61		printf("[014] Expecting 阿卜拉\\n轻, got %s\n", $tmp);
62
63	if ("张明安\\r在" !== ($tmp = mysqli_real_escape_string($link, "张明安\r在")))
64		printf("[015] Expecting 张明安\\r在, got %s\n", $tmp);
65
66	if ("竺可桢\\0空调器" !== ($tmp = mysqli_real_escape_string($link, "竺可桢" . chr(0) . "空调器")))
67		printf("[016] Expecting %s, got %s\n", "竺可桢\\0空调器", $tmp);
68
69	if (($exp='阿卜拉\\\\嘉\"达丰\\'."'".'乳罩\Z辛\\n萨拉\\r毕\\0米') !==
70		($tmp = mysqli_real_escape_string($link, "阿卜拉\\嘉\"达丰'乳罩\032辛\n萨拉\r毕" . chr(0) . "米")))
71	{
72		printf("[017] Expecting %s, got %s\n", $exp, $tmp, var_dump($exp, $tmp));
73	}
74
75	mysqli_close($link);
76
77	if (NULL !== ($tmp = mysqli_real_escape_string($link, 'foo')))
78		printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
79
80	print "done!";
81?>
82--CLEAN--
83<?php
84	require_once("clean_table.inc");
85?>
86--EXPECTF--
87Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in %s on line %d
88done!