php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43967 SUM query on null value provides error in result with PDO_MYSQL driver
Submitted: 2008-01-29 15:29 UTC Modified: 2008-01-29 16:06 UTC
From: emilien dot colotte at free dot fr Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2.5 OS: Vista
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 !
Your email address:
MUST BE VALID
Solve the problem:
23 + 24 = ?
Subscribe to this entry?

 
 [2008-01-29 15:29 UTC] emilien dot colotte at free dot fr
Description:
------------
I made a simple sum query on a table column.
The column contains some integer values and some null values.
By executing the query throught the PDO MySQL driver, the result is wrong.
By using the classic mysql library in PHP, the result is ok.

I think there is a bug in PDO MySQL driver.

More informations:
- MySQL Version: 5.0.45
- PHP version: 5.2.4

Reproduce code:
---------------
CREATE TABLE `TEST` (
  `ID_TEST` int(10) NOT NULL AUTO_INCREMENT,
  `VALUE` int(10) default NULL
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO TEST (ID_TEST, VALUE) VALUES (1, NULL);
INSERT INTO TEST (ID_TEST, VALUE) VALUES (2, -1);

SELECT SUM(VALUE) AS TOTAL FROM TEST;

Expected result:
----------------
The value returned by the query must be -1.


Actual result:
--------------
By executing the query from PDO, the value returned is NULL
By executing the query from MySQL library, the value returned is -1 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-29 16:06 UTC] emilien dot colotte at free dot fr
This is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 11:01:31 2024 UTC