mirror of
https://github.com/standardebooks/web.git
synced 2025-07-12 17:42:29 -04:00
Improve handling of returning patrons
This commit is contained in:
parent
dbefba6b94
commit
32206f3cd7
10 changed files with 61 additions and 55 deletions
20
lib/Db.php
20
lib/Db.php
|
@ -19,4 +19,24 @@ class Db{
|
|||
|
||||
return $GLOBALS['DbConnection']->Query($query, $args, $class);
|
||||
}
|
||||
|
||||
public static function QueryInt(string $query, array $args = []): int{
|
||||
// Useful for queries that return a single integer as a result, like count(*) or sum(*).
|
||||
|
||||
if(!isset($GLOBALS['DbConnection'])){
|
||||
$GLOBALS['DbConnection'] = new DbConnection(DATABASE_DEFAULT_DATABASE, DATABASE_DEFAULT_HOST);
|
||||
}
|
||||
|
||||
if(!is_array($args)){
|
||||
$args = [$args];
|
||||
}
|
||||
|
||||
$result = $GLOBALS['DbConnection']->Query($query, $args);
|
||||
|
||||
if(sizeof($result) > 0){
|
||||
return current((Array)$result[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue