YourPaste - For your paste! Archive - Tools - Login

Posted by unknown on Tue 18 Nov 2008 13:54 174 views - Syntax: PHP - Expires: never - Report - IMG - Download -

  1. <?php
  2.  
  3. class db
  4. {
  5.         private $con;
  6.         private $res;
  7.         private $fa = 1; // 1 voor fetch_assoc - 2 voor fetch_array - 3 voor fetch_object - 4 voor fetch_row
  8.        
  9.         public $iQuerys=0;     
  10.         public $querys;
  11.        
  12.         public $qtime = 0;
  13.        
  14.         public function connect($user,$pass,$db,$host)
  15.         {
  16.                 $this->con = mysql_connect($host,$user,$pass) or $this->error();
  17.                 mysql_select_db($db) or $this->error();
  18.         }
  19.        
  20.         public function query($query)
  21.         {
  22.                 $startquerytime = microtime_float();
  23.                 $this->res = mysql_query($query,$this->con) or $this->error($query);
  24.                 $this->qtime += microtime_float()-$startquerytime;
  25.                
  26.                 $this->iQuerys++;
  27.                 $this->querys .= $query."\r\n\r\n";
  28.  
  29.                 return $this->res;
  30.         }
  31.  
  32.         public function fetch_array($res=0)
  33.         {
  34.                 if ($res==0)
  35.                 {
  36.                         $res = $this->res;
  37.                 }
  38.  
  39.                 return mysql_fetch_array($res);
  40.         }
  41.        
  42.         public function fetch_assoc($res=0)
  43.         {
  44.                 if ($res==0)
  45.                 {
  46.                         $res = $this->res;
  47.                 }
  48.  
  49.                 return mysql_fetch_assoc($res);
  50.         }
  51.  
  52.         public function fetch_object($res=0)
  53.         {
  54.                 if ($res==0)
  55.                 {
  56.                         $res = $this->res;
  57.                 }
  58.  
  59.                 return mysql_fetch_object($res);
  60.         }
  61.  
  62.         public function fetch_row($res=0)
  63.         {
  64.                 if($res==0)
  65.                 {
  66.                         $res = $this->res;
  67.                 }
  68.                
  69.                 return mysql_fetch_row($res);
  70.         }
  71.        
  72.         public function fa($query) //verkorte query + fetch actie
  73.     {
  74.         $res = $this->query($query);
  75.        
  76.         switch($this->fa)
  77.         {        
  78.                 case 1:
  79.                         return $this->fetch_assoc($res);
  80.                         break;
  81.                 case 2:
  82.                         return $this->fetch_array($res);
  83.                         break;
  84.                 case 3:
  85.                         return $this->fetch_object($res);
  86.                         break;
  87.                 case 4:
  88.                         return $this->fetch_row($res);
  89.                 break;
  90.         }
  91.     }
  92.        
  93.         public function num_rows($res=0)
  94.         {
  95.                 if ($res==0)
  96.                 {
  97.                         $res = $this->res;
  98.                 }
  99.  
  100.                 return mysql_num_rows($res);
  101.         }
  102.  
  103.         public function affected_rows()
  104.         {
  105.                 return mysql_affected_rows($this->con);
  106.         }
  107.        
  108.         public function insert_id()
  109.         {
  110.                 return mysql_insert_id($this->con);
  111.         }
  112.        
  113.         public function escape($str)
  114.         {
  115.                 return mysql_real_escape_string($str, $this->con);
  116.         }
  117.  
  118.         public function disconnect()
  119.         {
  120.                 mysql_close($this->con);
  121.         }
  122.        
  123.         private function error($query)
  124.         {
  125.                 die(mysql_error() . PHP_EOL);
  126.         }
  127. }
  128.  
  129. ?>

Comments


Name:
Comment:

© 2008 YourPaste.net - Disclaimer