Created
October 22, 2014 11:38
-
-
Save saaiful/4413e501bf6bf4c668f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class myClass | |
{ | |
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(); | |
} | |
} | |
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