Last active
August 11, 2016 00:19
-
-
Save kfriend/4a4b36d5c3143b5feb12 to your computer and use it in GitHub Desktop.
PHP: Very simple PDO DB wrapper
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 Db | |
{ | |
protected $connection; | |
public function __construct(PDO $connection) | |
{ | |
$this->connection = $connection; | |
} | |
public function select($query, array $arguments = array()) | |
{ | |
try { | |
$stmt = $this->connection->prepare($query); | |
$stmt->execute($arguments); | |
} catch(Exception $e) { | |
return null; | |
} | |
$stmt->setFetchMode(PDO::FETCH_INTO, new StdClass); | |
return $stmt->fetchAll(); | |
} | |
public function insert($query, array $data = array()) | |
{ | |
try { | |
$stmt = $this->connection->prepare($query); | |
return $stmt->execute($data); | |
} catch(Exception $e) { | |
return null; | |
} | |
} | |
public function getConnection() | |
{ | |
return $this->connection; | |
} | |
public function setConnection(PDO $connection) | |
{ | |
$this->connection = $connection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment