Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. class Database{
  4.  
  5.         public $result;
  6.  
  7.         public function __construct(){
  8.            
  9.             $dbHost = "localhost";
  10.             $dbUser = "root";
  11.             $dbPass = "";
  12.             $dbName = "portal";
  13.             $this->conn = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die(mysql_error());
  14.             $mydb = mysql_select_db("$dbName") or die(mysql_error());
  15.             return $this->conn;
  16.            
  17.         }
  18.        
  19.         public function execute(){    
  20.             $query = $this->sql;
  21.             $result = mysql_query($query);
  22.             return $this->result;
  23.         }
  24.        
  25.         public function listall(){
  26.                
  27.             $this->execute();
  28.             $data = array();
  29.            
  30.             while($fetch = mysql_fetch_assoc($this->result)){
  31.                 $data[] = $fetch;
  32.             }
  33.            
  34.             return $data;
  35.         }
  36.        
  37.         public function fetch_row(){
  38.             $this->execute();
  39.             $fetch = mysql_fetch_row($this->result);
  40.             $this->data = $fetch;
  41.             return $this->data;
  42.         }
  43.      
  44. }
  45.  
  46.  
  47. --------------------------------------------------------------------------------------------
  48.  
  49.  
  50.  
  51. <?php require_once('database.php'); ?>
  52.  
  53. <?php
  54.  
  55. class User extends Database{
  56.  
  57.     public function validate_login($username, $password){
  58.    
  59.         $this->sql = "SELECT username, password FROM users WHERE username='". $username ."' AND password='". $password . "'";
  60.         $result = $this->execute();
  61.        
  62.         if(mysql_num_rows($result) == 1) {
  63.        
  64.             return TRUE;   
  65.         }
  66.             return FALSE;
  67.     }
  68.  
  69.     public function insert($tablename, $username, $password, $email_address){
  70.    
  71.         $this->sql = "INSERT INTO $tablename(username, password, email_address) VALUES('$username','$password','$email_address')";
  72.         $result = $this->execute();
  73.        
  74.         if($result){
  75.            
  76.             return TRUE;
  77.        
  78.         } else {
  79.        
  80.             return FALSE;
  81.        
  82.         }
  83.            
  84.     }
  85. }
  86.  
  87. $me = new User();
  88.  
  89.  
  90.  
  91. $me->insert('users', 'a', 'a','a');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement