PDO::query() executes an SQL statement in
a single function call, returning the result set (if any) returned by the
statement as a PDOStatement object.

For a query that you need to issue multiple times, you will realize better
performance if you prepare a PDOStatement object using
PDO::prepare() and issue the statement with multiple
calls to PDOStatement::execute().

If you do not fetch all of the data in a result set before issuing your
next call to PDO::query(), your call may fail. Call
PDOStatement::closeCursor() to release the database
resources associated with the PDOStatement object before issuing your
next call to PDO::query().

Note:

Although this function is only documented as having a single
parameter, you may pass additional arguments to this function.
They will be treated as though you called
PDOStatement::setFetchMode() on the resultant statement
object.

After a lot of hours working with DataLink on Oracle->MySQL and PDO we (me and Adriano Rodrigues, that solve it) discover that PDO (and oci too) need the attribute AUTOCOMMIT set to FALSE to work correctly with.There's 3 ways to set autocommit to false: On constructor, setting the atribute after construct and before query data or initiating a Transaction (that turns off autocommit mode)

The examples:<?php// First way - On PDO Constructor$options = array(PDO::ATTR_AUTOCOMMIT=>FALSE);

$pdo = new PDO($dsn,$user,$pass,$options);

// now we are ready to query DataLinks

?>

<?php // Second Way - Before create statements$pdo = new PDO($dsn,$user,$pass);

If someone is suffering of the "MySQL server has gone away" problem after executing multiple queries, this is a solution that solved it for me. It's similar to the one needed for the exact same problem in mysqli.

I found this method extremely useful for getting the iteration count. Note the usage of "for" instead of "while" or "foreach". Just place the "$row = $query->fetch()" as the second condition of your for loop (which is do until). This is the best of both worlds IMHO. Criticism welcome.