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