-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathpdo_mysql_attr_multi_statements.phpt
101 lines (95 loc) · 2.76 KB
/
pdo_mysql_attr_multi_statements.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
--TEST--
PDO::MYSQL_ATTR_MULTI_STATEMENTS
--EXTENSIONS--
pdo_mysql
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
?>
--INI--
error_reporting=E_ALL
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$dsn = MySQLPDOTest::getDSN();
$user = PDO_MYSQL_TEST_USER;
$pass = PDO_MYSQL_TEST_PASS;
$table = sprintf("test_%s", md5(mt_rand(0, PHP_INT_MAX)));
$db = new PDO($dsn, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));
$create = sprintf('CREATE TABLE %s(id INT)', $table);
$db->exec($create);
$db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table));
$stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (2)', $table, $table));
$stmt->closeCursor();
$info = $db->errorInfo();
var_dump($info[0]);
$stmt = $db->query(sprintf('SELECT id FROM %s', $table));
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
// A single query with a trailing delimiter.
$stmt = $db->query('SELECT 1 AS value;');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
// New connection, does not allow multiple statements.
$db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => false));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (3)', $table, $table));
var_dump($stmt);
$info = $db->errorInfo();
var_dump($info[0]);
$stmt = $db->query(sprintf('SELECT id FROM %s', $table));
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
// A single query with a trailing delimiter.
$stmt = $db->query('SELECT 1 AS value;');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));
print "done!";
?>
--EXPECTF--
string(5) "00000"
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
array(1) {
[0]=>
array(1) {
["value"]=>
string(1) "1"
}
}
Warning: PDO::query(): 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 'INSERT INTO %s(id) VALUES (3)' at line 1 in %s on line %d
bool(false)
string(5) "42000"
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
array(1) {
[0]=>
array(1) {
["value"]=>
string(1) "1"
}
}
done!