a pastebin project

Untitled

  1. <?php
  2.  
  3. class db  {
  4.         function __construct() {
  5.                 $this->link = mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS);
  6.                 $this->Args = func_get_args();
  7.                 if(count($this->Args) == 0) {
  8.                         $this->db = mysql_select_db(MYSQL_DB);
  9.                 }
  10.                 else {
  11.                         $this->db = mysql_select_db($this->Args[0]);
  12.                 }
  13.     }
  14.  
  15.     function getResult($result) {
  16.         $i=0;
  17.                 while($olddata = mysql_fetch_assoc($result)) {
  18.                         $keys = array_keys($olddata);
  19.                         foreach($keys as $key) {
  20.                                 $newdata[$i][$key] = stripslashes($olddata[$key]);
  21.                         }
  22.                         $i++;
  23.                 }
  24.                 return $newdata;
  25.     }
  26.  
  27.     function query($sql) {
  28.  
  29.                 $result = mysql_query($sql) or die($sql . " " . mysql_error());
  30.                 return $result;
  31.         }
  32.  
  33.         function update($table, $data, $key, $value) {
  34.                 $i=0;
  35.                 $count = count($data) - 1;
  36.                 foreach($data as $k=> $item) {
  37.                         if(preg_match("/date/", $k)) {
  38.                                 $item = date("Y-m-d H:i:s", strtotime($item));
  39.                         }
  40.  
  41.                         if($i==$count) {
  42.                                 $sql .= $k . " = '" . mysql_real_escape_string($item) . "'";
  43.                         }
  44.                         else {
  45.                                 $sql .= $k . " = '" . mysql_real_escape_string($item) . "', ";
  46.                         }
  47.                         $i++;
  48.                 }
  49.                 $sql = "UPDATE " . $table . " SET " . $sql . ", last_update = NOW() WHERE " . $key . " = '" . $value . "'";
  50.  
  51.                 if($this->validate($table, $data)) {
  52.                         $result = $this->query($sql);
  53.                         return $result;
  54.                 }
  55.                 else {
  56.                         return false;
  57.                 }
  58.         }
  59.  
  60.         function remove($table, $key, $value) {
  61.                 $sql = "DELETE FROM " . $table . " WHERE " . $key . " = '" . $value . "'";
  62.                 $result = $this->query($sql);
  63.                 return result;
  64.         }
  65.  
  66.         function add($table, $data) {
  67.                 $i=0;
  68.                 $count = count($data) - 1;
  69.                 foreach($data as $k=> $item) {
  70.                         if(preg_match("/date/", $k)) {
  71.                                 $item = date("Y-m-d H:i:s", strtotime($item));
  72.                         }
  73.  
  74.                         if($i == $count) {
  75.                                 $field_sql .= $k;
  76.                                 $data_sql .= "'"mysql_real_escape_string($item) . "'";
  77.                         }
  78.  
  79.                         else {
  80.                                 $field_sql .= $k . ", ";
  81.                                 $data_sql .= "'" . mysql_real_escape_string($item) . "',";
  82.                         }
  83.  
  84.                         $i++;
  85.                 }
  86.                 $sql = "INSERT INTO " . $table . "  (" . $field_sql . ", last_update, created) VALUES(".$data_sql.", NOW(), NOW())";
  87.                 if($this->validate($table, $data)) {
  88.                         $result = $this->query($sql);
  89.                         return $result;
  90.                 }
  91.                 else {
  92.                         return false;
  93.                 }
  94.         }
  95.  
  96.     function getData($table, $select_field = "*", $where_field, $value) {
  97.                 $sql = "SELECT " . $select_field . " FROM " . $table . " WHERE " . $where_field . " = '" . $value . "'";
  98.                 $result = $this->query($sql);
  99.                 $newdata = $this->getResult($result);
  100.                 return $newdata;
  101.     }
  102.  
  103.         function getInsertID() {
  104.                 return mysql_insert_id();
  105.         }
  106. }
  107. ?>

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords.

worth-right fantasy-obligation