In addition to reusing the query, the main reason to use prepared statements in the PDO is to bind to the placeholder.
$query = self::$DB->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $query->execute($bindvars);
In this code, question mark tags (or :named ) present in the $sql variable are replaced with the values in the $bindvars . This replacement ensures that the variables are correctly quoted and escaped, making SQL injection difficult.
There may be a small amount of overhead in preparation / execution, but small overhead does not pose a danger to SQL injection. The only other option is to concatenate the SQL string, and this can be a huge security risk, unless it performs perfectly every time .
The previous developer knew what he or she was doing, at least in this particular case, and you should not cancel the work that he or she did here. Otherwise, you should continue to use prepared statements in all of your future code.
(On the other hand, I cannot vouch for the performance of the MySQL cursor ...)
source share