Guest User

Untitled

a guest
Aug 21st, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.  
  3.     class Database {
  4.    
  5.         public $hostname = "hostname";
  6.         public $username = "username";
  7.         public $password = "password";
  8.         public $database = "database";
  9.        
  10.         public function __construct() {
  11.        
  12.             if( !mysqli_real_connect( $this->hostname, $this->username, $this->password, $this->database ) ) {
  13.                 die( "<h1>MySQLi Error:</h1><hr>" . mysqli_connect_error() . "<hr>" );
  14.             }
  15.        
  16.         }
  17.        
  18.         public function query( $string ) {
  19.        
  20.             $q = mysqli_query( $string );
  21.             if( !$q ) { die( "<h1>MySQLi Error:</h1><hr>" . mysqli_error() . "<hr>" ); }
  22.             return $q;
  23.        
  24.         }
  25.        
  26.         public function arr( $string, $lazy = false ) {
  27.        
  28.             return $lazy != false ? mysqli_fetch_array( $this->query( $string ) ) : mysqli_fetch_array( $string );
  29.        
  30.         }
  31.        
  32.         public function assoc( $string, $lazy = false ) {
  33.        
  34.             return $lazy != false ? mysqli_fetch_assoc( $this->query( $string ) ) : mysqli_fetch_assoc( $string );
  35.        
  36.         }
  37.        
  38.         public function num( $string, $lazy = false ) {
  39.        
  40.             return $lazy != false ? mysqli_num_rows( $this->query( $string ) ) : mysqli_num_rows( $string );
  41.        
  42.         }
  43.        
  44.         public function escape( $string ) {
  45.        
  46.             return mysqli_real_escape_string( $string );
  47.        
  48.         }
  49.    
  50.     }
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment