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: -
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: andre at webkr dot de Assigned:
Status: Open Package: PDO MySQL
PHP Version: 7.0.5 OS: Windows + Mac
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
24 + 12 = ?
Subscribe to this entry?

 
 [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

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 10:01:25 2019 UTC