xref: /PHP-8.2/ext/pdo_mysql/tests/bug66528.phpt (revision 72f47c0c)
1--TEST--
2Bug #66528: No PDOException or errorCode if database becomes unavailable before PDO::commit
3--EXTENSIONS--
4pdo
5pdo_mysql
6--SKIPIF--
7<?php
8require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
9MySQLPDOTest::skip();
10?>
11--FILE--
12<?php
13require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14
15$dbh = MySQLPDOTest::factory();
16$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
18
19$dbh->exec('DROP TABLE IF EXISTS test');
20$dbh->exec('CREATE TABLE test (a int) engine=innodb');
21$dbh->beginTransaction();
22$dbh->exec('INSERT INTO test (a) VALUES (1), (2)');
23$stmt = $dbh->query('SELECT * FROM test');
24
25try {
26	$dbh->commit();
27} catch (PDOException $e) {
28	echo $e->getMessage(), "\n";
29}
30
31try {
32	$dbh->rollBack();
33} catch (PDOException $e) {
34	echo $e->getMessage(), "\n";
35}
36
37try {
38    $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
39} catch (PDOException $e) {
40	echo $e->getMessage(), "\n";
41}
42
43?>
44--CLEAN--
45<?php
46require __DIR__ . '/mysql_pdo_test.inc';
47MySQLPDOTest::dropTestTable();
48?>
49--EXPECT--
50SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
51SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
52SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
53