xref: /PHP-7.4/ext/pdo/tests/bug_71447.phpt (revision 26dfce7f)
1--TEST--
2PDO Common: Bug #71447 (Quotes inside comments not properly handled)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15
16$db = PDOTest::factory();
17$db->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
18$db->setAttribute (\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_NUM);
19$db->setAttribute (\PDO::ATTR_EMULATE_PREPARES, false);
20$db->exec('CREATE TABLE test(id int)');
21$db->exec('INSERT INTO test VALUES(1)');
22
23// Comment without quotes or placeholders
24$stmt = $db->prepare("
25	SELECT -- Thats all folks!
26		'\"abc\":8000'
27	FROM test
28");
29
30$stmt->execute();
31var_dump($stmt->fetchColumn());
32
33// Comment and placeholder within a string
34$stmt = $db->prepare("
35	SELECT
36		'\"abc\":8001 -- Wat?'
37	FROM test
38");
39
40$stmt->execute();
41var_dump($stmt->fetchColumn());
42
43// Comment with single quote
44$stmt = $db->prepare("
45	SELECT -- That's all folks!
46		'\"abc\":8002'
47	FROM test
48");
49
50$stmt->execute();
51var_dump($stmt->fetchColumn());
52
53// C-Style comment with single quote
54$stmt = $db->prepare("
55	SELECT /* That's all folks! */
56		'\"abc\":8003'
57	FROM test
58");
59
60$stmt->execute();
61var_dump($stmt->fetchColumn());
62
63// Comment with double quote
64$stmt = $db->prepare("
65	SELECT -- Is it only \"single quotes?
66		'\"abc\":8004'
67	FROM test
68");
69
70$stmt->execute();
71var_dump($stmt->fetchColumn());
72
73// Comment with ? placeholder
74$stmt = $db->prepare("
75	SELECT -- What about question marks here?
76		*
77	FROM test
78	WHERE id = ?
79");
80
81$stmt->execute([1]);
82var_dump($stmt->fetchColumn());
83
84// Comment with named placeholder
85$stmt = $db->prepare("
86	SELECT -- What about placeholders :bar
87		*
88	FROM test
89	WHERE id = :id
90");
91
92$stmt->execute(['id' => 1]);
93var_dump($stmt->fetchColumn());
94
95
96?>
97--EXPECT--
98string(10) ""abc":8000"
99string(18) ""abc":8001 -- Wat?"
100string(10) ""abc":8002"
101string(10) ""abc":8003"
102string(10) ""abc":8004"
103string(1) "1"
104string(1) "1"
105