xref: /php-src/ext/pdo_mysql/tests/bug54929.phpt (revision 4bb75d56)
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__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13$pdodb = MySQLPDOTest::factory();
14
15function testQuery($query) {
16    global $pdodb;
17    $stmt = $pdodb->prepare($query);
18
19    if (!$stmt->execute(["foo"])) {
20        var_dump($stmt->errorInfo());
21    } else{
22        var_dump($stmt->fetch(PDO::FETCH_ASSOC));
23    }
24}
25
26testQuery("/* ' */ SELECT ? AS f1 /* ' */");
27testQuery("/* '-- */ SELECT ? AS f1 /* *' */");
28testQuery("/* ' */ SELECT ? AS f1 --';");
29testQuery("/* ' */ SELECT ? AS f1 -- 'a;");
30testQuery("/*'**/ SELECT ? AS f1 /* ' */");
31testQuery("/*'***/ SELECT ? AS f1 /* ' */");
32testQuery("/*'**a ***b / ****
33******
34**/ SELECT ? AS f1 /* ' */");
35
36?>
37--EXPECTF--
38array(1) {
39  ["f1"]=>
40  string(3) "foo"
41}
42array(1) {
43  ["f1"]=>
44  string(3) "foo"
45}
46
47Warning: 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
48array(3) {
49  [0]=>
50  string(5) "42000"
51  [1]=>
52  int(1064)
53  [2]=>
54  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"
55}
56array(1) {
57  ["f1"]=>
58  string(3) "foo"
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}
72