xref: /PHP-7.4/ext/pdo_mysql/tests/bug63185.phpt (revision bd093ad8)
1--TEST--
2Bug #63185: nextRowset() ignores MySQL errors with native prepared statements
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$pdo = MySQLPDOTest::factory();
15$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16
17$pdo->exec('DROP PROCEDURE IF EXISTS test_procedure_error_at_second');
18$pdo->exec('CREATE PROCEDURE test_procedure_error_at_second ()
19	BEGIN
20		SELECT "x" as foo;
21		SELECT * FROM no_such_table;
22	END');
23
24$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
25$st = $pdo->query('CALL test_procedure_error_at_second()');
26var_dump($st->fetchAll());
27try {
28    var_dump($st->nextRowset());
29} catch (PDOException $e) {
30    echo $e->getMessage(), "\n";
31}
32unset($st);
33
34$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
35$st = $pdo->query('CALL test_procedure_error_at_second()');
36var_dump($st->fetchAll());
37try {
38    var_dump($st->nextRowset());
39} catch (PDOException $e) {
40    echo $e->getMessage(), "\n";
41}
42var_dump($st->fetchAll());
43
44?>
45--EXPECTF--
46array(1) {
47  [0]=>
48  array(2) {
49    ["foo"]=>
50    string(1) "x"
51    [0]=>
52    string(1) "x"
53  }
54}
55SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.no_such_table' doesn't exist
56array(1) {
57  [0]=>
58  array(2) {
59    ["foo"]=>
60    string(1) "x"
61    [0]=>
62    string(1) "x"
63  }
64}
65SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.no_such_table' doesn't exist
66array(0) {
67}
68