Created
March 7, 2016 03:50
-
-
Save besingamkb/1602f4ea334a10ccc320 to your computer and use it in GitHub Desktop.
pdo php
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 | |
class Database { | |
protected $host = 'localhost'; | |
protected $user = 'root'; | |
protected $pass = ''; | |
protected $dbname = 'family'; | |
protected $db; | |
protected $sql_query; | |
protected $result; | |
public function __construct() { | |
$this->db = new PDO("mysql:host=".$this->host.";dbname=".$this->dbname, $this->user, $this->pass); | |
$this->db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); | |
} | |
public function query($query = null) { | |
//$this->sql_query = $query; | |
$sql = ($query != null) ? $query : $this->sql_query; | |
try { | |
//$query | |
$q = $this->prepare($sql); | |
$result = $q->execute(); | |
$thi->result = $result; | |
} catch(PDOException $e) { | |
die("ERROR: " . $e->getMesage()); | |
} | |
} | |
public function select($items) { | |
$this->sql_query .= "SELECT $items"; | |
} | |
public function from($table) { | |
$this->sql_query .= " FROM $table"; | |
} | |
public function where($fields, $value) { | |
$this->sql_query .= " WHERE $fields = $value"; | |
} | |
public function get_data() { | |
return $this->result; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment