Lexiconga/php/helpers.php

35 lines
1013 B
PHP
Raw Normal View History

<?php
// Simplified PHP functions
function query ($query_string) {
$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);
$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;
}
}
function num_rows ($query_results) {
try {
$rowcount = $query_results->rowcount();
return $rowcount;
}
catch (PDOException $ex) {
return false;
}
}
function fetch ($query_results) {
try {
$fetchassoc = $query_results->fetch();
return $fetchassoc;
}
catch (PDOException $ex) {
return false;
}
}
?>