This method converts a PDOStatement object into an Iterator object, making it convenient for iterating over the result set of the PDOStatement. The returned Iterator represents each row of the result set.
Return Value:
Returns an Iterator representing the PDOStatement object.
<?php
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->query('SELECT * FROM mytable');
$iterator = $stmt->getIterator();
foreach ($iterator as $row) {
print_r($row);
}
$stmt = null;
$pdo = null;
?>