Advertisement
Guest User

Untitled

a guest
Nov 9th, 2011
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1.     /** Sends given query to MySQL server
  2.      * @param string format
  3.      * @param mixed arguments
  4.      * @return MySQLResult       
  5.     */
  6.     static public function query($format) {
  7.  
  8.         if( !is_resource(self::$connection) ) throw new Exception('Connection to MySQL server has not been established yet');
  9.  
  10.         $arguments = func_get_args();
  11.         unset($arguments[0]);
  12.  
  13.         // Renumber arguments array
  14.         $arguments = array_merge($arguments, array());
  15.  
  16.         // Escape strings
  17.         foreach($arguments as $i=>$arg) {
  18.             if( is_string($arg) ) $arguments[$i] = mysql_escape_string($arg);
  19.         }
  20.  
  21.         $sql = vsprintf($format, $arguments);
  22.         $result = @mysql_query($sql, self::$connection);
  23.         if( !$result ) throw new Exception(mysql_error(), mysql_errno());
  24.         return new MySQLResult($result);
  25.  
  26.     }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement