|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57112 "SELECT AVG(score) from ScoreTable" fails using PDO
Submitted: 2006-06-27 15:28 UTC Modified: 2006-10-13 07:11 UTC
From: grady at solutionset dot com Assigned:
Status: Not a bug Package: PDO (PECL)
PHP Version: 5.1.2 OS: Debain Linux
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:
Solve the problem:
32 - 21 = ?
Subscribe to this entry?

 [2006-06-27 15:28 UTC] grady at solutionset dot com
Using MySQL math functions through PDO seems to throw a bothersome error that is not thrown when using the traditional mysql extension or by running the query directly on the database.

Using AVG or SUM in PDO throws mysql error 2036

"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2036..."

This has been confirmed to work with a standard conection using mysql_connect(), mysql_select_db(), mysql_query(), and mysql_fetch_array()

Reproduce code:
CREATE TABLE `MemberRating` (
  `MemberRatingId` int(11) NOT NULL auto_increment,
  `ContentEntryInfoId` int(11) default NULL,
  `value` int(11) default NULL,
  PRIMARY KEY  (`MemberRatingId`)

//add in several random numeric values for the
//ContentEntryInfoId of 191

$query = 'SELECT AVG(value) FROM MemberRating WHERE ContentEntryInfoId = 191';

$dbh = new PDO($dsn, $user, $password);
$sth = $dbh->prepare($query);
$result = $sth->fetchAll(PDO::FETCH_ASSOC);

Expected result:
    [0] => Array
            [avg(value)] => 3.2000


Actual result:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2036 '


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-25 04:16 UTC] d49228002 at ym dot edu dot tw
I've the same bug, but the php file can be executed in command line. However, once I executed the same php file from web browser, the same erroe happen.

OS: red hat enterprise linux 4
Apache: apache 2.0.52
DB: mysql 5.0.22
PHP: 5.1.4 with latest PDO, PDO_mysql
 [2006-10-12 19:13 UTC] joel dot alexandre at gmail dot com
This also happens to me.
The query 
"SELECT STDDEV(total_size) FROM site_crawl WHERE id_site = 1"
works well but 
"SELECT AVG(total_size) FROM site_crawl WHERE id_site = 1" and 
"SELECT SUM(total_size) FROM site_crawl WHERE id_site = 1"
give the error already reported.

I'm using:
Ubuntu 6.06
PHP Version 5.1.6-0.dotdeb.2
PDO Driver for MySQL, client library version	4.1.15
 [2006-10-12 20:02 UTC] joel dot alexandre at gmail dot com
I forgot to say my mysql version

5.0.24 and also tried 5.0.22.
 [2006-10-13 04:37 UTC] joel dot alexandre at gmail dot com
This isn't a bug.

I had this problem because pdo_mysql was compiled with mysql 4.1.? and  i had mysqlclient 5.0.22 installed.

I just recompiled pdo_mysql and the problem was solved.

More details here:
 [2006-10-13 04:39 UTC] joel dot alexandre at gmail dot com
Sorry, the details are here:
 [2006-10-13 07:11 UTC]
User reports that this is not a bug.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Feb 27 15:01:28 2020 UTC