1--TEST--
2mysqli_real_escape_string() - SQL Mode NO_BACKSLASH_ESCAPE
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	require_once('table.inc');
13
14	if (!mysqli_query($link, 'SET @@sql_mode="NO_BACKSLASH_ESCAPES"'))
15		printf("[001] Cannot set NO_BACKSLASH_ESCAPES, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
16
17	if ('\\' !== ($tmp = mysqli_real_escape_string($link, '\\')))
18		printf("[002] Expecting \\, got %s\n", $tmp);
19
20	if ('"' !== ($tmp = mysqli_real_escape_string($link, '"')))
21		printf("[003] Expecting \", got %s\n", $tmp);
22
23	if ("''" !== ($tmp = mysqli_real_escape_string($link, "'")))
24		printf("[004] Expecting '', got %s\n", $tmp);
25
26	if ("\n" !== ($tmp = mysqli_real_escape_string($link, "\n")))
27		printf("[005] Expecting \\n, got %s\n", $tmp);
28
29	if ("\r" !== ($tmp = mysqli_real_escape_string($link, "\r")))
30		printf("[006] Expecting \\r, got %s\n", $tmp);
31
32	assert("foo" . chr(0) . "bar" === "foo" . chr(0) . "bar");
33	if ("foo" . chr(0) . "bar" !== ($tmp = mysqli_real_escape_string($link, "foo" . chr(0) . "bar")))
34		printf("[007] Expecting %s, got %s\n", "foo" . chr(0) . "bar", $tmp);
35
36	if (!mysqli_query($link, sprintf('INSERT INTO test(id, label) VALUES (100, "%s")',
37			mysqli_real_escape_string($link, "\\"))))
38		printf("[009] Cannot INSERT, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
39
40	if (!($res = mysqli_query($link, 'SELECT label FROM test WHERE id = 100')) ||
41			!($row = mysqli_fetch_assoc($res)))
42		printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43
44	var_dump($row);
45	mysqli_free_result($res);
46
47	if (!mysqli_query($link, 'SET @@sql_mode=""'))
48		printf("[011] Cannot disable NO_BACKSLASH_ESCAPES, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
49
50	if ('\\\\' !== ($tmp = mysqli_real_escape_string($link, '\\')))
51		printf("[012] Expecting \\, got %s\n", $tmp);
52
53	if ("foo\\0bar" !== ($tmp = mysqli_real_escape_string($link, "foo" . chr(0) . "bar")))
54		printf("[013] Expecting %s, got %s\n", "foo" . chr(0) . "bar", $tmp);
55
56	mysqli_close($link);
57
58	print "done!";
59?>
60--EXPECTF--
61array(1) {
62  ["label"]=>
63  string(1) "\"
64}
65done!
66