SHARE
TWEET

Untitled

a guest Nov 9th, 2011 440 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top