xref: /PHP-7.4/ext/pdo_mysql/tests/bug66528.phpt (revision 68dcaa29)
1--TEST--
2Bug #66528: No PDOException or errorCode if database becomes unavailable before PDO::commit
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13
14$dbh = MySQLPDOTest::factory();
15$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
17
18$dbh->exec('DROP TABLE IF EXISTS test');
19$dbh->exec('CREATE TABLE test (a int) engine=innodb');
20$dbh->beginTransaction();
21$dbh->exec('INSERT INTO test (a) VALUES (1), (2)');
22$stmt = $dbh->query('SELECT * FROM test');
23
24try {
25	$dbh->commit();
26} catch (PDOException $e) {
27	echo $e->getMessage(), "\n";
28}
29
30try {
31	$dbh->rollBack();
32} catch (PDOException $e) {
33	echo $e->getMessage(), "\n";
34}
35
36try {
37    $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
38} catch (PDOException $e) {
39	echo $e->getMessage(), "\n";
40}
41
42?>
43--CLEAN--
44<?php
45require __DIR__ . '/mysql_pdo_test.inc';
46MySQLPDOTest::dropTestTable();
47?>
48--EXPECT--
49SQLSTATE[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.
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.
52