How does PHP PDO work internally ?

Posted by Rachel on Stack Overflow See other posts from Stack Overflow or by Rachel
Published on 2010-03-26T21:55:39Z Indexed on 2010/03/26 22:03 UTC
Read the original article Hit count: 362

Filed under:
|

I want to use pdo in my application, but before that I want to understand how internally PDOStatement->fetch and PDOStatement->fetchAll.

For my application, I want to do something like "SELECT * FROM myTable" and insert into csv file and it has around 90000 rows of data.

My question is, if I use PDOStatement->fetch as I am using it here:

// First, prepare the statement, using placeholders
$query = "SELECT * FROM tableName";
$stmt = $this->connection->prepare($query);

// Execute the statement
$stmt->execute();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
{
echo "Hi";
// Export every row to a file
fputcsv($data, $row);
}

Will after every fetch from database, result for that fetch would be store in memory ?

Meaning when I do second fetch, memory would have data of first fetch as well as data for second fetch.

And so if I have 90000 rows of data and if am doing fetch every time than memory is being updated to take new fetch result without removing results from previous fetch and so for the last fetch memory would already have 89999 rows of data.

  1. Is this how PDOStatement::fetch works ?
  2. Performance wise how does this stack up against PDOStatement::fetchAll ?

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo