php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57146 PDO->query returns false reguardless of query
Submitted: 2006-07-19 09:19 UTC Modified: 2008-09-12 10:52 UTC
From: jason at shaped dot ca Assigned:
Status: Closed Package: PDO (PECL)
PHP Version: 5.1.4 OS: Linux, Fedora Core 5
Private report: No CVE-ID: None
 [2006-07-19 09:19 UTC] jason at shaped dot ca
Description:
------------
I am actually using PHP 5.1.4, theres no option for that in the list.

Whenever I try to do a PDO->query, false is returned even if rows should have been returned (I've checked and re-checked the SQL against a table to absolutely ensure that data should be returned).

I have classes that use PDO's that worked perfectly right before I upgraded to MySQL 5.

I've recompiled PHP and double checked everything I can, but I can not figure out this issue and Google hasn't been any help so my best guess is either my configuration is out of wack (which I'm 99% sure it's fine) or I've stumbled across a bug.

System: Linux circle 2.6.17-1.2157_FC5 #1 Tue Jul 11 22:53:11 EDT 2006 i686
Build Date: Jul 18 2006 07:35:33
Configure Command:
'./configure' '--with-mysql' '--with-gd' '--with-xpm' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-bz2' '--with-curl' '--with-freetype-dir=/usr' '--with-png-di=/usr' '--enable-gd-native-ttf' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-pear=/usr/share/pear' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--with-mime-magic=/etc/httpd/conf/magic' '--with-libxml-dir=/usr' '--with-xml' '--with-apxs2=/usr/sbin/apxs' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--libexecdir=/usr/libexec' '--with-libdir=lib' '--with-config-file-path=/etc' '--enable-mbstring' '--enable-mbstring-enc-trans' '--enable-pcntl' '--with-xsl' '--with-tidy' '--enable-pdo=shared' '--with-pdo-mysql=shared,/usr/local/mysql' '--with-sqlite=shared' '--with-pdo-sqlite=shared'

PDO
PDO support	enabled
PDO drivers 	mysql

pdo_mysql
PDO Driver for MySQL, client library version	5.0.22

Reproduce code:
---------------
test.php:
<?php
try {
   $dbh = new PDO('mysql:host=localhost;dbname=$db', $user, $pass);
   foreach ($dbh->query('SELECT * from FOO') as $row) {
     print_r($row);
   }
   $dbh = null;
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}
?>


Expected result:
----------------
Expected table rows to be printed.



Actual result:
--------------
PHP Warning:  Invalid argument supplied for foreach() in /root/test.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-21 17:39 UTC] bugs at xmlnode dot com
I'll be honest I was surprised your code worked for me because I thought you had to call fetch() to get at the data, but I had no problems with it.  Have you tried using fetch()?

something like:
$result = $db->query("SELECT * FROM FOO");
while( $row = $result->fetch(PDO::FETCH_ASSOC) ){
    print_r($row);
}

just a thought.
 [2006-07-21 19:22 UTC] jason at shaped dot ca
I took that code straight out of the PHP manual.

It also matches the type of query made with www.phpobjectgenerator.com.
 [2006-07-23 06:02 UTC] jason at shaped dot ca
I still cannot place what has caused this issue, however after some playing, I've got my PDO working again, I'm using php5.2-200607230830 now though.

If no one can reproduce this on php5.1.4 / mysql5.0.22, then close this.
 [2006-08-08 15:06 UTC] ian_mcmurray at utb dot uscourts dot gov
I'm running Fedora Core 5 with PHP 5.1.4 - trying to get pdf_informix to retrieve a simple row of data from 1 table and hit the same issue!

This works...
foreach ($dbh->query('select * from case where cs_caseid = 258579');

But this doesn't:
foreach ($dbh->query('select * from case where cs_caseid = 258588');

I've verified record existance in the table. This should work - such a simple query.

Any ideas? (apart from maybe a buggy PHP version 5.1.4?)
 [2006-08-08 15:07 UTC] ian_mcmurray at utb dot uscourts dot gov
Whoops - I meant PDO_informix not PDF_informix !!
 [2006-08-08 15:34 UTC] ian_mcmurray at utb dot uscourts dot gov
This problem is still present with the alpha version (1.0.1) of PDO_INFORMIX.
 [2006-09-07 04:29 UTC] wiik dot andreas at gmail dot com
I have the same problem in php 5.1.2 and mysql 4.0.12.
 [2006-09-07 06:21 UTC] jason at shaped dot ca
I should note I've been using php5.2-200607230830 since first encountering this bug and have had no troubles.
 [2006-12-14 03:47 UTC] rysenko at gmail dot com
I'm experiencing the same trouble on PHP 5.2.0 (final). My query is very simple:
$stmt = $conn->query('SELECT * FROM articles');
And it returns false, table exists and has rows in it, and connections is ok. I have no troubles with regular mysql extension.

I'm using PHP 5.2.0 on Windows + PDO + PDO_MYSQL.
 [2006-12-14 04:56 UTC] rysenko at gmail dot com
I've tried more and and it came out, that this was due to malformed connection DSN. But it threw no exception and I thought connection was ok.

I've used it in this WRONG way: "mysql://localhost/dbname" (didn't care to read the doc). I even misspelled my password and got exception, fixed password and got no exception, thought it was ok. Anyway, I think exception should be thrown in case of wrong DSN, or not being able to select database.
 [2008-09-12 10:52 UTC] johannes at schlueters dot de
There's an error now
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 21:01:28 2024 UTC