Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Datamanager {
- public $hostName = 'localhost';
- public $dbName = 'stackoverflow';
- public $dbUser = 'xxx';
- public $dbPassword = 'xxx';
- public function __construct() {
- try {
- $this->dbh = new PDO("mysql:host=$this->hostName;dbname=$this->dbName", $this->dbUser, $this->dbPassword);
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- public function runQuery($query, $obj){
- try {
- $STH = $this->dbh->prepare($query);
- $STH->bindParam(':id', $obj->user_id);
- $STH->setFetchMode(PDO::FETCH_INTO, $obj);
- $STH->execute();
- $STH->fetch();
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- return $obj;
- }
- }
- class User {
- public $user_id;
- public $user_name;
- public $user_password;
- public $session_id;
- private $dbc;
- public function __construct() {
- $this->dbc = new Datamanager();
- }
- function selectUser ($userID, $obj) {
- $this->user_id = $userID;
- $query = 'SELECT user_id, user_name, user_password, session_id FROM users WHERE user_id=:id';
- $results = $this->dbc->runQuery($query, $this);
- }
- }
- $userID = "1";
- $test = new User;
- $test->selectUser($userID, $test);
- var_dump($test);
Add Comment
Please, Sign In to add comment