Advertisement
brainode

ConnectDB

Feb 14th, 2014
60
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. /**
  3.  * Created by PhpStorm.
  4.  * User: asus
  5.  * Date: 2/10/14
  6.  * Time: 7:22 PM
  7.  */
  8.  
  9. namespace core\classes;
  10.  
  11.  
  12. class db{
  13.     private $db_host,$db_name,$db_login,$db_pass;
  14.     protected $result,$select,$where,$connect;
  15.     public  function connect(){
  16.         $this->connect=mysqli_connect($this->db_host,$this->db_login,$this->db_pass,$this->db_name);
  17.     }
  18.     protected function setSelect($select){
  19.         $this->select=$select;
  20.     }
  21.     public function setWhere($where){
  22.         $this->where=$where;
  23.     }
  24.     public function select($tableName){
  25.         $coma='`';
  26.         $table=$tableName;
  27.         if($this->where!=false){
  28.             $flag=true;
  29.         }
  30.         switch($flag):
  31.             case true:
  32.                 $query="SELECT ".$coma.$this->select.$coma." FROM ".$coma.$this->db_name.$coma.".".$table.$coma." WHERE ".$this->where.";";
  33.                 break;
  34.             case false:
  35.                 $query="SELECT ".$coma.$this->select.$coma." FROM ".$coma.$this->db_name.$coma.".".$coma.$table.$coma.";";
  36.                 break;
  37.         endswitch;
  38.         $result=mysqli_query($this->connect,$query);
  39.         return $result;
  40.     }
  41.     public function __construct(){
  42.         $this->db_host="localhost";
  43.         $this->db_name="*****";
  44.         $this->db_login="*****";
  45.         $this->db_pass="*********";
  46.         $this->result=false;
  47.         $this->select=false;
  48.         $this->where=false;
  49.         $this->connect=false;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement