2015-11-02 17:25:08 -07:00
|
|
|
<?php
|
|
|
|
// Simplified PHP functions
|
|
|
|
function query ($query_string) {
|
2015-11-25 16:08:24 -07:00
|
|
|
$dbconnection = new PDO('mysql:host=' . DATABASE_SERVERNAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD);
|
|
|
|
$dbconnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
2015-11-27 23:17:52 -07:00
|
|
|
$dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
2015-11-25 16:08:24 -07:00
|
|
|
$dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
|
|
|
try {
|
|
|
|
$queryResults = $dbconnection->prepare($query_string);
|
|
|
|
$queryResults->execute();
|
|
|
|
return $queryResults;
|
|
|
|
}
|
|
|
|
catch (PDOException $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-04 14:12:39 -07:00
|
|
|
}
|
2015-11-02 17:25:08 -07:00
|
|
|
function num_rows ($query_results) {
|
2015-11-25 16:08:24 -07:00
|
|
|
try {
|
|
|
|
$rowcount = $query_results->rowcount();
|
|
|
|
return $rowcount;
|
|
|
|
}
|
|
|
|
catch (PDOException $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-02 17:25:08 -07:00
|
|
|
}
|
2015-11-25 16:08:24 -07:00
|
|
|
function fetch ($query_results) {
|
|
|
|
try {
|
|
|
|
$fetchassoc = $query_results->fetch();
|
|
|
|
return $fetchassoc;
|
|
|
|
}
|
|
|
|
catch (PDOException $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-02 17:25:08 -07:00
|
|
|
}
|
|
|
|
?>
|