|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 19:00:02 2025 UTC |
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?