Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class main
- {
- private $host = "localhost";
- private $user = "root";
- private $pass = "";
- private $db = "laboratory";
- private $insert_first = array();
- private $insert_last = array();
- private $update = array();
- public function __construct() {
- $this->link = mysql_connect("$this->host","$this->user","$this->pass");
- mysql_select_db($this->db,$this->link);
- }
- public function insert($tbl,$data) {
- $this->tbl = $tbl;
- foreach ($this->data = $data as $name=>$value)
- {
- $this->insert_first[] = $name;
- $this->insert_last[]= mysql_real_escape_string($value);
- $this->results[$name] = $value;
- }
- $this->insert_first = '('.implode(',',$this->insert_first).')';
- $this->insert_last = "('".implode("','",$this->insert_last)."')";
- mysql_query("INSERT INTO $this->tbl $this->insert_first VALUES $this->insert_last ") or die (mysql_error());
- return ($this->results);
- }
- public function update ($tbl,$uid,$data){
- $this->tbl = $tbl;
- $this->uid = $uid;
- foreach ($this->data = $data as $name=>$value){
- $value = mysql_real_escape_string($value);
- $this->update[] = "$name = '$value'";
- }
- $this->update = implode (',',$this->update) ;
- mysql_query("UPDATE $this->tbl SET $this->update WHERE id='$this->uid' ") or die (mysql_error());
- echo ("UPDATE `$this->tbl` SET $this->update WHERE id='$this->uid' ");
- }
- public function select ($tbl,$uid){
- $this->tbl = $tbl;
- $this->uid = $uid;
- if (empty($this->uid))
- $this->result = mysql_query("SELECT * FROM $this->tbl")or die (mysql_error());
- if (!empty($this->uid))
- $this->result = mysql_query("SELECT * FROM $this->tbl WHERE id='$this->uid'")or die (mysql_error());
- $this->return = array () ;
- while ($this->row = mysql_fetch_array( $this->result )) {
- $this->return [] = $this->row ;
- }
- return ($this->return);
- }
- public function delete($tbl,$data){
- $this->tbl = $tbl;
- $this->data = $data;
- foreach ($this->data as $this->value=>$this->key)
- {
- mysql_query("DELETE FROM $this->tbl WHERE id='$this->key'");
- }
- }
- public function __destruct() {
- mysql_close($this->link);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement