UPDATED: There is an issue whereby this code does not work as expected with MySQL. As a result, the concept has been reworked and listed under the entry " Consolidated query executions version 2 ." In an effort to adhere to the DRY principle, or don't repeat yourself , the routine defined in this piece can be added to programs that employ a series of queries. The idea is that it moves a few lines of code that would otherwise need to be in each method or function that calls a query to a database server. This snippet is coded with PHP and represents a method from a larger class. There are more details about the code itself in the comments of the code. private function run($sql) { // Assumes $this->Conn has been set up in advance as a PDO connection. $Query = $this->Conn->prepare($sql); if((func_num_args() == 2) && is_array(func_get_arg(1))) { $Query->execute(func_get_arg(1)); } else { $Query->execute(array()); } // ...
A little commentary about the world of
technology and programming. No "holy wars,"
or ideological rants, just posts about tech
news and other findings from around various
places.