xref: /php-src/ext/pdo_mysql/tests/bug66528.phpt (revision 4bb75d56)
1--TEST--
2Bug #66528: No PDOException or errorCode if database becomes unavailable before PDO::commit
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$dbh = MySQLPDOTest::factory();
14
15$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
17
18$dbh->exec('CREATE TABLE test_66528 (a INT) ENGINE=InnoDB');
19$dbh->beginTransaction();
20$dbh->exec('INSERT INTO test_66528 (a) VALUES (1), (2)');
21$stmt = $dbh->query('SELECT * FROM test_66528');
22
23try {
24	$dbh->commit();
25} catch (PDOException $e) {
26	echo $e->getMessage(), "\n";
27}
28
29try {
30	$dbh->rollBack();
31} catch (PDOException $e) {
32	echo $e->getMessage(), "\n";
33}
34
35try {
36    $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
37} catch (PDOException $e) {
38	echo $e->getMessage(), "\n";
39}
40
41?>
42--CLEAN--
43<?php
44require_once __DIR__ . '/inc/mysql_pdo_test.inc';
45$db = MySQLPDOTest::factory();
46$db->exec('DROP TABLE IF EXISTS test_66528');
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