daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Aug 14th, 2018 64 in 178 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. final class db{
  3.     static $db;
  4.    
  5.     static function config($conf=false){
  6.         #echo '<pre>'.print_r($conf, 1).'</pre>';
  7.         self::$db = mysql_connect($conf['host'], $conf['username'], $conf['password']);
  8.         mysql_select_db($conf['database'], self::$db);
  9.     }
  10.  
  11.     static function changedb($database){
  12.         $resp = mysql_select_db($database);
  13.         return($resp);
  14.     }
  15.    
  16.     static function select($sql, $args=false){
  17.        
  18.         if($args['pager']){
  19.             $limit = self::load_pager($args['pager']);
  20.             $sql .= 'LIMIT '.$limit;
  21.         }
  22.        
  23.         $result = mysql_query($sql, self::$db);
  24.         if(!$result) trigger_error("MySQL SELECT error: ".mysql_error()." using ".$sql);
  25.  
  26.         if(@$args['explain']==true) self::explain($sql);
  27.        
  28.         while ($r = mysql_fetch_array($result,MYSQL_ASSOC)){
  29.                 $row[] = $r;
  30.         }
  31.  
  32.  
  33.         mysql_free_result($result);
  34.  
  35.         @array_walk_recursive($row, 'de_clean_post_recursive');
  36.         return @$row;
  37.     }
  38.    
  39.     static function select_row($sql, $args=false){
  40.             $result = mysql_query($sql, self::$db);
  41.             if(!$result) trigger_error("MySQL SELECT error: ".mysql_error()." using ".$sql);
  42.            
  43.             if(@$args['explain']==true) self::explain($sql);
  44.            
  45.             $row = mysql_fetch_array($result,MYSQL_ASSOC);         
  46.             mysql_free_result($result);
  47.  
  48.             @array_walk_recursive($row, 'de_clean_post_recursive');                
  49.             return @$row;
  50.     }
  51.  
  52.     static function query($sql)
  53.     {
  54.         $result = mysql_query($sql, self::$db);
  55.         if(!$result) trigger_error("MySQL UPDATE error: ".mysql_error().'<pre>'.$sql.'</pre><br>');
  56.         #if($_SESSION['access'] == 'admin') recache($sql);
  57.     }
  58.    
  59.     static function explain($sql){
  60.        
  61.         trigger_error("SQL: ".$sql);
  62.         $explain = mysql_query("EXPLAIN {$sql}", self::$db);
  63.         if ($row = mysql_fetch_assoc($explain)) {
  64.             foreach ($row as $key => $value) {
  65.                 trigger_error("$key: $value\n");
  66.             }
  67.         }
  68.  
  69.     }
  70.    
  71.    
  72. }
  73. ?>
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