I am writing a database class for my site with functions such as fetchOne , fetchAll that cook, execute (+ bind) and query all in one, so I do not need to individually name those functions each time. Some cron jobs on my site run thousands or even millions of requests within a loop.
Will using my class result in the operator having to be processed every iteration of the loop, or does the PDO “remember” that the request has already been prepared? Will this significantly affect performance, and if it could be a solution, just provide a function that passes the database instance and do something like $db->getDb()->prepare($query); out of cycle? Or is there a better solution?
Function example:
public function fetchOne($query, $params = array(), $fetchMode = PDO::FETCH_ASSOC) { $stmt = self::prepareExecute($query, $params); $result = $stmt->fetch($fetchMode); if (count($result) < 1) $result = FALSE; $stmt->closeCursor(); unset($stmt); return($result); }
source share