ekoheri

mysql.php

May 30th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. class mysql {
  3.     private $conn;
  4.     private $server = 'localhost';
  5.     private $user = 'root';
  6.     private $password = '';
  7.     private $database = 'latihan';
  8.  
  9.     public function connect() {
  10.         if(isset($this->conn)) return $this->conn;
  11.         $this->conn = @mysql_connect($this->server,$this->user,$this->password, true) or die ("Unable connect to mysql server.");
  12.         @mysql_select_db($this->database, $this->conn) or die("Unable to select your default database name.");
  13.     }
  14.     public function disconnect(){
  15.         if(isset($this->conn)) {
  16.             @mysql_close($this->conn);
  17.         }
  18.     }
  19.     public function query($sql){
  20.         $result = @mysql_query($sql, $this->conn);
  21.         if (!$result) {
  22.                 die (mysql_error());
  23.         }
  24.         return $result;
  25.     }
  26.     public function results($query, $type = 'object'){
  27.         $result = $this->query($query);
  28.         $return = array();
  29.         while ($row = @mysql_fetch_object($result)) {
  30.             if($type == 'array')
  31.                 $return[] = (array) $row;
  32.             else
  33.                 $return[] = $row;
  34.         }
  35.         @mysql_free_result($result);
  36.         return @$return;
  37.     }
  38. }//end class
  39. ?>
Add Comment
Please, Sign In to add comment