php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72076 PDO ignores MySQL errors when using server-side prepared statements
Submitted: 2016-04-22 11:32 UTC Modified: 2020-10-28 15:20 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: andre at webkr dot de Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.0.5 OS: Windows + Mac
Private report: No CVE-ID: None
 [2016-04-22 11:32 UTC] andre at webkr dot de
Description:
------------
When using server-side prepared statements, MySQL errors happening during execution are not returned by PDO MySQL.

This happens in PHP 5.6 and PHP 7.0.

Test script:
---------------
$p = new PDO('mysql:host=localhost;charset=utf8', 'root', '', array(PDO::MYSQL_ATTR_COMPRESS => false));

$p->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // server

$p->query('CREATE DATABASE IF NOT EXISTS fixture');
$p->query('DROP TABLE IF EXISTS fixture.MysqlDatabaseTest');
$p->query('CREATE TABLE fixture.MysqlDatabaseTest (MysqlDatabaseTest_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT NOT NULL) ENGINE=MyISAM');
$p->query('INSERT INTO fixture.MysqlDatabaseTest SET i = 1');
$p->query('INSERT INTO fixture.MysqlDatabaseTest SET i = 42');

$s = $p->prepare('SELECT i FROM fixture.MysqlDatabaseTest WHERE i = (SELECT i FROM fixture.MysqlDatabaseTest)');

$success = $s ? $s->execute() : null;;

var_dump($success, $s, $p->errorInfo());
if ($s)
	var_dump($s->errorInfo(), $s->fetchAll());


Expected result:
----------------
Error: Subquery returns more than 1 row

Actual result:
--------------
No error, `$s->fetchAll()` returns an empty result array.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-28 15:20 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-10-28 15:20 UTC] nikic@php.net
This is another issue fixed by https://github.com/php/php-src/commit/b03776adb5bbb9b54731a44377632fcc94a59d2f. An error is properly reported on current PHP-7.4 HEAD.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 09:01:24 2020 UTC