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