ID: 46429 Updated by: [EMAIL PROTECTED] Reported By: balustefan at gmail dot com -Status: Open +Status: Bogus Bug Type: PDO related Operating System: FreeBSD 7.0-RELEASE i386 PHP Version: 5.2.6 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php See: http://docs.php.net/manual/en/pdostatement.columncount.php No result set == no query executed. (like prepare() not followed by execute()) Previous Comments: ------------------------------------------------------------------------ [2008-10-30 12:24:37] balustefan at gmail dot com Description: ------------ Seems like columnCount() returns invelid int value. No mater how many results match a query, columnCount() will return int(3). Even for no results. The underlying database is sqlite3-3.5.6 Reproduce code: --------------- 1. create an sql table in a freshly database file: sqlite> create table hosts(hw char(18), > ip varchar(16), > extra text, > constraint hw_pkey primary key(hw)); 2. insert some data into it: sqlite> insert into hosts values('00:19:21:57:44:f8','89.122.239.55','comment'); sqlite> insert into hosts values('00:e0:4c:20:dc:15','194.102.255.234','some comment'); 3. use a php function like this one to fetch a "host": function fetchHost($hwAddr) { $sqlQuery = "SELECT * FROM hosts WHERE hw = ?"; if (($sqlStatement = $sqlPDO->prepare($sqlQuery)) === false) return (bool) false; if ($sqlStatement->execute(array($hwAddr)) === false) return (bool) false; var_dump($sqlStatement->columnCount()); if ($sqlStatement->columnCount() < 1) return (bool) true; return $sqlStatement->fetch(PDO::FETCH_ASSOC); } Expected result: ---------------- The output of var_dump() should be 0 if no rows are found, and number of rows if all is ok. Actual result: -------------- On 0 or more rows returned, columnCount() returns int(3). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46429&edit=1