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