SHARE
TWEET

Untitled

a guest Apr 26th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Datamanager {
  4.     public $hostName = 'localhost';
  5.     public $dbName = 'stackoverflow';
  6.     public $dbUser = 'xxx';
  7.     public $dbPassword = 'xxx';
  8.    
  9.     public function __construct() {
  10.         try {
  11.             $this->dbh = new PDO("mysql:host=$this->hostName;dbname=$this->dbName", $this->dbUser, $this->dbPassword);
  12.         } catch(PDOException $e) {
  13.             echo $e->getMessage();
  14.         }
  15.     }
  16.     public function runQuery($query, $obj){
  17.         try {
  18.             $STH = $this->dbh->prepare($query);
  19.                         $STH->bindParam(':id', $obj->user_id);
  20.  
  21.             $STH->setFetchMode(PDO::FETCH_INTO, $obj);
  22.                         $STH->execute();
  23.                         $STH->fetch();
  24.         } catch(PDOException $e) {
  25.             echo $e->getMessage();
  26.         }
  27.         return $obj;
  28.     }
  29. }
  30.  
  31. class User {
  32.     public $user_id;
  33.     public $user_name;
  34.     public $user_password;
  35.     public $session_id;
  36.     private $dbc;
  37.  
  38.     public function __construct() {
  39.         $this->dbc = new Datamanager();
  40.     }
  41.  
  42.     function selectUser ($userID, $obj) {
  43.                 $this->user_id = $userID;
  44.         $query = 'SELECT user_id, user_name, user_password, session_id FROM users WHERE user_id=:id';
  45.         $results = $this->dbc->runQuery($query, $this);
  46.     }
  47. }
  48.  
  49. $userID = "1";
  50. $test = new User;
  51.  
  52. $test->selectUser($userID, $test);
  53.  
  54. var_dump($test);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top