Skip to content

Instantly share code, notes, and snippets.

@saaiful
Created October 22, 2014 11:38
Show Gist options
  • Save saaiful/4413e501bf6bf4c668f7 to your computer and use it in GitHub Desktop.
Save saaiful/4413e501bf6bf4c668f7 to your computer and use it in GitHub Desktop.
<?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