Skip to content

Instantly share code, notes, and snippets.

@maxxon15
Forked from JeremyMorgan/database.class.php
Created April 16, 2013 19:20
Show Gist options
  • Save maxxon15/5398776 to your computer and use it in GitHub Desktop.
Save maxxon15/5398776 to your computer and use it in GitHub Desktop.
<?php
/**
* File: database.class.php
* Super simple PDO class
*
* Author: Jeremy Morgan
*
* This is just a start. No error handling or parameterization yet
*/
class Database {
public $dbh; // database object
private $result; // result set
private function getDbh() {
return $this->dbh;
}
private function setDbh($x) {
$this->dbh = $x;
}
#Constructor
public function __construct() {
#probaby best to store the credentials in a config file
setDbh = new PDO('<SERVERTYPE>:host=<SERVER> ;dbname=<SOMEDB>', '<USERNAME>', '<PASSWORD>');
}
#Execute a query
function query($qry) {
$this->result = $this->dbh->query($qry);
$this->result->execute;
}
#Show result set as an object
function fetchobject() {
$row = $this->result->fetch(PDO::FETCH_OBJ);
return $row;
}
#Show result set as an array
function fetcharray() {
$row = $this->result->fetch(PDO::FETCH_ASSOC);
return $row;
}
#Show result set as a number
function fetchnum() {
$row = $this->result->fetch(PDO::FETCH_NUM);
return $row;
}
#Count total number of rows in database
function checkrowCount() {
$count = count($this->result->fetchAll());
return $count;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment