2

Why do we use PDO::closeCursor() method/function in PDO PHP?

Basically this question is asked already there but the answers are not contextual that can give a clear output that why PDO::closeCursor() is used?

When should I use closeCursor() for PDO statements?

On php.net its definition is too summarized that one cannot understand after reading it.

PHP.NET->pdo::closeCursor()

Can anyone tell? Examples will be more useful for better understanding.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • These aren't commonly used. Do you have a use case? Also why was this tagged `mysqli` when that's a completely different interface? – tadman Feb 21 '18 at 20:27
  • Your question leads me to the question whether one can break from an pdo while fetch loop, execute another query and come back to the 1st query and continue where you left off? Can this result in performance gains when fetching huge set of records? And why does this function not return a id to reference the query from memory? – Nitin Feb 21 '18 at 20:29
  • @Nitin - Yea please do one experiment and then .... Me also trying here to see what will happen !!! –  Feb 21 '18 at 21:03

2 Answers2

2

Some databases does not support to execute and fetch the result from the next query until the previous query has the un-fetched results.

Let suppose you are executing 2 queries, the first one is in the fetching state and is not completed yet and on the same moment you want the first query to be stop in the state where it is currently in, and want to move to next query so the PDO::closeCursor() is used between the two queries to pause the first query in the same state and begin the next one.

Remember: This method is not compatible with all the PDO drivers.

0

You could use it if you're halfway in reading the result of a SQL query, and you don't care about reading the rest.

Evert
  • 93,428
  • 18
  • 118
  • 189