2015-11-03 01:25:08 +01:00
|
|
|
<?php
|
|
|
|
// Simplified PHP functions
|
|
|
|
function query ($query_string) {
|
2015-11-26 00:08:24 +01: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-28 07:17:52 +01:00
|
|
|
$dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
2015-11-26 00:08:24 +01: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 22:12:39 +01:00
|
|
|
}
|
2015-11-03 01:25:08 +01:00
|
|
|
function num_rows ($query_results) {
|
2015-11-26 00:08:24 +01:00
|
|
|
try {
|
|
|
|
$rowcount = $query_results->rowcount();
|
|
|
|
return $rowcount;
|
|
|
|
}
|
|
|
|
catch (PDOException $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-03 01:25:08 +01:00
|
|
|
}
|
2015-11-26 00:08:24 +01:00
|
|
|
function fetch ($query_results) {
|
|
|
|
try {
|
|
|
|
$fetchassoc = $query_results->fetch();
|
|
|
|
return $fetchassoc;
|
|
|
|
}
|
|
|
|
catch (PDOException $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-03 01:25:08 +01:00
|
|
|
}
|
|
|
|
?>
|