Bug #72798 [NEW]: SELECT COUNT() returns string, not int.

From: Date: Tue, 09 Aug 2016 19:12:07 +0000
Subject: Bug #72798 [NEW]: SELECT COUNT() returns string, not int.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203126@lists.php.net to get a copy of this message
From:             php dot chaska at xoxy dot net
Operating system: FreeBSD, Mac OSX
PHP version:      5.6.24
Package:          PDO SQLite
Bug Type:         Bug
Bug description:SELECT COUNT() returns string, not int.

Description:
------------
---
From manual page: http://www.php.net/pdostatement.fetchcolumn
---
With this SQL statement

SELECT count(*) FROM my_table;

fetchColumn() returns an INTEGER with Postgres and a STRING with Sqlite.
That is, if there is one row in the table, Postgres returns (int)1 and
Sqlite returns '1'.

Note that

SELECT TYPEOF(b) FROM ( select count(*) as b from my_table) a;

produces integer in Sqlite.

See also
http://stackoverflow.com/questions/38857255/php-pdo-postgres-versus-sqlite-column-type-for-count



Test script:
---------------
http://pastebin.com/arGpxjm7

Expected result:
----------------
I expect both Postgres and Sqlite to return an integer type from
fetchColumn() in both cases, since that is what the database claims it
is returning.  That is, I expect this result from my test script:

Postgres: int(1)
Sqlite3:  int(1)

Actual result:
--------------
Postgres: int(1)
Sqlite3:  string(1) "1"

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72798&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72798&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72798&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72798&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72798&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72798&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72798&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72798&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72798&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72798&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72798&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72798&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72798&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72798&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72798&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72798&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72798&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72798&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72798&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72798&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72798&r=mysqlcfg



Thread (10 messages)

« previous php.bugs (#203126) next »