Skip to content

Instantly share code, notes, and snippets.

@KCreate
Created February 26, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KCreate/74f45a438028f115aa7f to your computer and use it in GitHub Desktop.
Save KCreate/74f45a438028f115aa7f to your computer and use it in GitHub Desktop.
EasyQuery
// Easier sql queries
class EasyQuery {
private $dbname;
private $db;
public function __construct($dbname) {
$this->dbname = $dbname;
// Check if the db file exists
if (!file_exists($this->dbname)) {
return false;
}
// Try to load the db
try {
$this->db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=".$this->dbname."; UID=Admin;");
} catch (Exception $e) {
echo $e;
return false;
}
return $this;
}
public function r($sql, $values) {
// Keep track of all results
$results = (object)[
'status' => false,
'rows' => []
];
// Prepare and execute the query
$query = $this->db->prepare($sql);
$results->status = $query->execute($values);
// Copy all the returned rows to the result object
while ($row = $query->fetch()) {
array_push($results->rows, $row);
}
return $results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment