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