|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-07-25 04:16 UTC] d49228002 at ym dot edu dot tw
[2006-10-12 19:13 UTC] joel dot alexandre at gmail dot com
[2006-10-12 20:02 UTC] joel dot alexandre at gmail dot com
[2006-10-13 04:37 UTC] joel dot alexandre at gmail dot com
[2006-10-13 04:39 UTC] joel dot alexandre at gmail dot com
[2006-10-13 07:11 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
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 '