php.net |  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
Votes:4
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
 [2014-01-30 12:25 UTC] a at enaza dot ru
Description:
------------
---
From manual page: http://www.php.net/pdostatement.columncount
---
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");
var_dump($rs->columnCount());

Expected result:
----------------
int(0)

Actual result:
--------------
int(3)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:

$sth->execute();

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] cmb@php.net
-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] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=339522
Log: Fix #66613: PDOStatement::columnCount and empty result sets
 [2016-06-29 12:53 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2016-06-29 12:53 UTC] cmb@php.net
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] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a5c1a2e21138607d8b9bf8581ee1ae47ff8621af
Log: Fix #66613: PDOStatement::columnCount and empty result sets
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC