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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 17:01:30 2025 UTC