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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: emilien dot colotte at free dot fr
New email:
PHP Version: OS:

 

 [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: Thu Apr 25 22:01:29 2024 UTC