php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: grady at solutionset dot com
New email:
PHP Version: OS:

 

 [2006-06-27 15:28 UTC] grady at solutionset dot com
Description:
------------
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);
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
print_r($result);

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

)

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:
http://paradigma.pt/ja/slog/index.php/2006/10/php-with-pdo_mysql-and-error-sqlstatehy000-general-error-2036-fixed.html
 [2006-10-13 04:39 UTC] joel dot alexandre at gmail dot com
Sorry, the details are here: http://paradigma.pt/ja/slog/index.php/2006/10/pdo_mysql_ubuntu_error_fixed.html
 [2006-10-13 07:11 UTC] wez@php.net
User reports that this is not a bug.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Feb 19 18:01:29 2020 UTC