Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Nov 9th, 2011  |  syntax: PHP  |  size: 0.76 KB  |  hits: 379  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.