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
|
|
|
}
|
2015-12-02 01:24:43 +01:00
|
|
|
|
2016-03-11 17:54:25 +01:00
|
|
|
function get_include_contents($filename) {
|
|
|
|
if (is_file($filename)) {
|
|
|
|
ob_start();
|
|
|
|
include $filename;
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-02 01:24:43 +01:00
|
|
|
function ordinal($number) {
|
|
|
|
// Retrieved from http://stackoverflow.com/a/3110033/3508346
|
|
|
|
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
|
|
|
|
if ((($number % 100) >= 11) && (($number%100) <= 13))
|
|
|
|
return $number. 'th';
|
|
|
|
else
|
|
|
|
return $number. $ends[$number % 10];
|
|
|
|
}
|
|
|
|
|
|
|
|
function time_elapsed($secs){
|
|
|
|
// Retrieved from http://php.net/manual/en/function.time.php#108581
|
|
|
|
$bit = array(
|
|
|
|
// ' year' => $secs / 31556926 % 12,
|
|
|
|
// ' week' => $secs / 604800 % 52,
|
|
|
|
// ' day' => $secs / 86400 % 7,
|
|
|
|
// ' hour' => $secs / 3600 % 24,
|
|
|
|
' minute' => $secs / 60 % 60,
|
|
|
|
' second' => $secs % 60
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($bit as $k => $v){
|
|
|
|
if($v > 1 || $v < 1)$ret[] = $v . $k . 's';
|
|
|
|
if($v == 1)$ret[] = $v . $k;
|
|
|
|
}
|
|
|
|
array_splice($ret, count($ret)-1, 0, 'and');
|
|
|
|
//$ret[] = 'ago.';
|
|
|
|
|
|
|
|
return join(' ', $ret);
|
|
|
|
}
|
2015-12-02 02:05:38 +01:00
|
|
|
|
|
|
|
function random_string($length = 10) {
|
|
|
|
// Retrieved from http://stackoverflow.com/a/4356295/3508346
|
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$charactersLength = strlen($characters);
|
|
|
|
$randomString = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
|
}
|
|
|
|
return $randomString;
|
|
|
|
}
|
2015-11-03 01:25:08 +01:00
|
|
|
?>
|