xref: /PHP-7.0/ext/pdo_mysql/tests/bug54929.phpt (revision ccb677ec)
1--TEST--
2Bug #54929 (Parse error with single quote in sql comment (pdo-mysql))
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8
9?>
10--FILE--
11<?php
12
13require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14
15$pdodb = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
16
17
18function testQuery($query) {
19	global $pdodb;
20	$stmt = $pdodb->prepare($query);
21
22	if (!$stmt->execute(array("foo"))) {
23		var_dump($stmt->errorInfo());
24	} else{
25		var_dump($stmt->fetch(PDO::FETCH_ASSOC));
26	}
27}
28
29testQuery("/* ' */ select ? as f1 /* ' */");
30testQuery("/* '-- */ select ? as f1 /* *' */");
31testQuery("/* ' */ select ? as f1 --';");
32testQuery("/* ' */ select ? as f1 -- 'a;");
33testQuery("/*'**/ select ? as f1 /* ' */");
34testQuery("/*'***/ select ? as f1 /* ' */");
35testQuery("/*'**a ***b / ****
36******
37**/ select ? as f1 /* ' */");
38
39?>
40--EXPECTF--
41array(1) {
42  ["f1"]=>
43  string(3) "foo"
44}
45array(1) {
46  ["f1"]=>
47  string(3) "foo"
48}
49
50Warning: 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
51array(3) {
52  [0]=>
53  string(5) "42000"
54  [1]=>
55  int(1064)
56  [2]=>
57  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"
58}
59array(1) {
60  ["f1"]=>
61  string(3) "foo"
62}
63array(1) {
64  ["f1"]=>
65  string(3) "foo"
66}
67array(1) {
68  ["f1"]=>
69  string(3) "foo"
70}
71array(1) {
72  ["f1"]=>
73  string(3) "foo"
74}
75