PDO problem

I have a script that functions using php’s mysql functions, and I would like to convert it to PDO. The problem I’m having is that when I make a second (or subsequent) query to the database, I get nothing back at all.

As an example, doing:
[php]
$foo = mysql_query(“SELECT * FROM table WHERE option = foo”);
$bar = mysql_query(“SELECT * FROM table WHERE option = bar”);
echo (empty($foo)) ? “foo is empty
” : “foo is not empty
”;
echo (empty($bar)) ? “bar is empty” : “bar is not empty”;
[/php]
outputs:
foo is not empty
bar is not empty
while doing:
[php]
$db = new PDO(“mysql:dbname=database”, “username”, “password”);
$foo = $db->query(“SELECT * FROM table WHERE option = foo”);
$bar = $db->query(“SELECT * FROM table WHERE option = bar”);
echo (empty($foo)) ? “foo is empty
” : “foo is not empty
”;
echo (empty($bar)) ? “bar is empty” : “bar is not empty”;
[/php]
outputs:
foo is not empty
bar is empty

Why do I get nothing at all on the second PDO query and what can I do to fix it?

Sponsor our Newsletter | Privacy Policy | Terms of Service