Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2. class app {
  3.     //server
  4.   var $server = 'localhost';
  5.     //database
  6.   var $dbase = '';
  7.     //username
  8.     var $user = 'root';
  9.     //pass
  10.     var $pass = '';
  11.     //connection id
  12.     var $connection = 0;
  13.    
  14.     /**
  15.      * app::app()
  16.      *
  17.      * @param $server
  18.      * @param $dbase
  19.      * @param $user
  20.      * @param $pass
  21.      * @return void
  22.      **/
  23.     function __construct($server = '', $dbase = '', $user = '', $pass = '') {
  24.         if ($server!=''){
  25.             $this->server = $server;    
  26.         }      
  27.         $this->dbase = $dbase;
  28.         $this->user = $user;
  29.         $this->pass = $pass;       
  30.     }
  31.     function connect() {
  32.         if ($this->server!='' && $this->dbase!=''){
  33.             $this->connection=mysql_connect($this->server,$this->user,$this->pass);
  34.             if ($this->connection){
  35.                 mysql_select_db($this->dbase,$this->connection);
  36.             }
  37.         }
  38.         mysql_query("SET NAMES UTF8;");
  39.         return ($this->connection);        
  40.     }
  41.     function disconnect() {
  42.         @mysql_close($this->connection);               
  43.     }
  44.     function free($result){
  45.         return mysql_free_result($result);
  46.     }
  47.     function query($sql='') {
  48.         //provjera da li smo spojeni na bazu i ako nismo onda pokusaj spajanja
  49.         if (!$this->connection){
  50.             $this->connect();          
  51.         }
  52.        
  53.         if ($this->connection && $sql!=''){
  54.         $record_set = mysql_query($sql);
  55.         if(mysql_errno() !=0){
  56.           echo $sql."<br>";
  57.           echo mysql_errno() . ": " . mysql_error() . "\n<hr>";
  58.         }
  59.             return $record_set;
  60.         } else {
  61.             return false;
  62.         }              
  63.     }
  64. } // class
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement