xref: /PHP-8.1/ext/pdo_mysql/tests/bug54929.phpt (revision b5a14e6c)
1--TEST--
2Bug #54929 (Parse error with single quote in sql comment (pdo-mysql))
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9
10?>
11--FILE--
12<?php
13
14require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
15
16$pdodb = PDOTest::test_factory(__DIR__ . '/common.phpt');
17
18
19function testQuery($query) {
20    global $pdodb;
21    $stmt = $pdodb->prepare($query);
22
23    if (!$stmt->execute(array("foo"))) {
24        var_dump($stmt->errorInfo());
25    } else{
26        var_dump($stmt->fetch(PDO::FETCH_ASSOC));
27    }
28}
29
30testQuery("/* ' */ select ? as f1 /* ' */");
31testQuery("/* '-- */ select ? as f1 /* *' */");
32testQuery("/* ' */ select ? as f1 --';");
33testQuery("/* ' */ select ? as f1 -- 'a;");
34testQuery("/*'**/ select ? as f1 /* ' */");
35testQuery("/*'***/ select ? as f1 /* ' */");
36testQuery("/*'**a ***b / ****
37******
38**/ select ? as f1 /* ' */");
39
40?>
41--EXPECTF--
42array(1) {
43  ["f1"]=>
44  string(3) "foo"
45}
46array(1) {
47  ["f1"]=>
48  string(3) "foo"
49}
50
51Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near '--'' at line 1 in %s on line %d
52array(3) {
53  [0]=>
54  string(5) "42000"
55  [1]=>
56  int(1064)
57  [2]=>
58  string(%d) "You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near '--'' at line 1"
59}
60array(1) {
61  ["f1"]=>
62  string(3) "foo"
63}
64array(1) {
65  ["f1"]=>
66  string(3) "foo"
67}
68array(1) {
69  ["f1"]=>
70  string(3) "foo"
71}
72array(1) {
73  ["f1"]=>
74  string(3) "foo"
75}
76