xref: /PHP-7.2/ext/pdo_mysql/tests/bug53782.phpt (revision 3e17b490)
1--TEST--
2PDO MySQL Bug #53782 (foreach throws irrelevant exception)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6require dirname(__FILE__) . '/config.inc';
7require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require dirname(__FILE__) . '/config.inc';
13require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
14$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
15
16$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17
18$res = $conn->query('SELECT 0');
19
20try {
21    $conn->query('ERROR');
22} catch (PDOException $e) {
23    echo "Caught: ".$e->getMessage()."\n";
24}
25
26foreach ($res as $k => $v) {
27    echo "Value: $v[0]\n";
28}
29
30echo "DONE";
31?>
32--CLEAN--
33<?php
34require dirname(__FILE__) . '/mysql_pdo_test.inc';
35MySQLPDOTest::dropTestTable();
36?>
37--EXPECTF--
38Caught: SQLSTATE[42000]: %s
39Value: 0
40DONE
41