Created
October 22, 2014 11:45
-
-
Save saaiful/58fc18247f71f11d9ff1 to your computer and use it in GitHub Desktop.
Another One
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DB Class | |
*/ | |
class DB | |
{ | |
public $db = ''; | |
private $host = 'localhost'; | |
private $dbname = 'card'; | |
private $dbuser = 'root'; | |
private $dbpass = ''; | |
function __construct() | |
{ | |
// While Class Init. This will connect database. | |
try | |
{ | |
$this -> db = new PDO('mysql:host='.$this->host.';dbname='.$this->dbname.';charset=utf8',$this->dbuser,$this->dbpass); | |
} | |
catch (PDOException $e) | |
{ | |
var_dump($e->getMessage()); | |
die(); | |
} | |
} | |
} | |
class myClass extends DB | |
{ | |
public function query() | |
{ | |
$query = $this->db -> prepare("SELECT * FROM client"); | |
$query -> execute(); | |
return $query -> fetchAll(); | |
} | |
} | |
// Testing | |
$test = new myClass(); | |
$data = $test -> query(); | |
var_dump($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment