|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66613 PDOStatement::columnCount and empty result sets
Submitted: 2014-01-30 12:25 UTC Modified: 2016-06-29 12:53 UTC
Avg. Score:2.0 ± 1.0
Reproduced:0 of 2 (0.0%)
From: a at enaza dot ru Assigned: cmb (profile)
Status: Closed Package: PDO related
PHP Version: Irrelevant OS:
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:
24 - 22 = ?
Subscribe to this entry?

 [2014-01-30 12:25 UTC] a at enaza dot ru
From manual page:
According to the documentation, PDOStatement::columnCount() should returns "0", if result set is empty, but i get count fields from query, see example.

Test script:
$pdo = new PDO("mysql:host={$host};dbname={$database}", $username, $password);
$rs = $pdo->query("SELECT 1,2,3 LIMIT 0");

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-02 15:48 UTC] jareas at thegeekbeaver dot net
I got confused on this one. According to documentation, it supposed to return "0" only if the result set does not exist. It is quite different from result set is empty, in my opinion.

What I understood from the documentation is if the $sth object does not have a result set it will return "0". This was illustrated by the documentation on this line:

$sth = $dbh->prepare("SELECT name, colour FROM fruit");

Here we still do not have a record set. Then, $sth->columnCount() call will return "0". But, after we actually run the query calling:


we should get the column count even if the result set is empty. Thats what I understood. What do you think?
 [2014-02-03 13:42 UTC] a at enaza dot ru
I think, statement "If there is no result set" could be defined twofold. It should to be clarified in the documentation.
 [2016-06-29 12:52 UTC]
-Summary: PDOStatement::columnCount in mysql +Summary: PDOStatement::columnCount and empty result sets -Status: Open +Status: Verified -Package: PDO MySQL +Package: PDO related -Assigned To: +Assigned To: cmb
 [2016-06-29 12:53 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #66613: PDOStatement::columnCount and empty result sets
 [2016-06-29 12:53 UTC]
-Status: Verified +Status: Closed
 [2016-06-29 12:53 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC]
Automatic comment on behalf of cmb
Log: Fix #66613: PDOStatement::columnCount and empty result sets
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 08 23:03:35 2021 UTC