Currently I use in my projects ADODB library for integration with the database.
I want to migrate to PDO, but I have a question about the consultations.
Currently, with the ADODB I do a query and use the row with the set numerous times using the method MoveFirst().
Example:
//I consultation
$rs = $conn->execute('select * from mytable');
//Loop through the results
while(!$rs->EOF) {
echo $rs->fields('name');
$rs->MoveNext();
}
//I move the "pointer" to the beginning of the list
$rs->MoveFirst();
//I can go over the results without needing to re-select
while(!$rs->EOF) {
echo $rs->fields('name');
$rs->MoveNext();
}
I wonder if there is any way similar in PDO, so I do not need to run the query again.
The goal is to avoid unnecessary queries on the bench more often since they use the same query.
I’m not sure why you want to loop through the result set more than once over the database connection. Why pull the data over the network again when you can just retrieve and save it the first time? But what you are looking for is a scrollable cursor, which isn’t supported by mysql. At least not through any PHP/MySQL driver. You may also want to look into buffered/unbuffered queries, which is supported by PDO.
PDO::CURSOR_SCROLL
http://www.php.net/manual/en/pdo.prepare.php