AbstractDatabase
extends PDO
in package
AbstractYes
A basic wrapper around php's PDO class.
The children of this class will expect to be passed an instance of TiqConfig. One of the main purposed of this class is to hide the host, user, password, etc when connecting
Tags
Table of Contents
Properties
- $cache_ttl : int
- $debug : bool
- $enable_cache : bool
- $query_counter : int
- $unique_queries : array<string|int, mixed>
- $conf : TiqConfig
- $db_name : string
- $dsn : string
- $error_message : string
- Base error message, this belongs in com_think's configuration class
- $host : string
- $password : string
- $port : string|null
- $query_cache : array<string|int, mixed>
- $user_name : string
Methods
- __construct() : mixed
- Parses Config info and sets some default options.
- clearCache() : void
- Clear the query cache completely or for a specific query
- errorMessage() : string
- Returns an error message that should be actionable. The information in the error message comes from the database.
- run() : PDOStatement|false
- Compresses a basic query down into one function.
- generateCacheKey() : string
- Generate a cache key for a query and its arguments
- parseConfig() : void
- Breaks down the TiqConfig Object.
- profileQuery() : void
- Profile a query for debugging purposes
- parseException() : array<string|int, string>
- Initial version of hint parsing code.
Properties
$cache_ttl
public
int
$cache_ttl
= 300
- Time-to-live for cached queries in seconds
$debug
public
bool
$debug
= false
Tags
$enable_cache
public
bool
$enable_cache
= true
- Whether query caching is enabled
$query_counter
public
int
$query_counter
= 0
- Counts the number of queries run
$unique_queries
public
array<string|int, mixed>
$unique_queries
= []
- Tracks statistics about unique queries
$conf
protected
TiqConfig
$conf
$db_name
protected
string
$db_name
$dsn
protected
string
$dsn
$error_message
Base error message, this belongs in com_think's configuration class
protected
string
$error_message
= 'An issue occurred, please contact ThinkIQ for Support and enable debugging'
Tags
$host
protected
string
$host
$password
protected
string
$password
$port
protected
string|null
$port
$query_cache
protected
array<string|int, mixed>
$query_cache
= []
- Caches query results for repeated queries
$user_name
protected
string
$user_name
Methods
__construct()
Parses Config info and sets some default options.
public
__construct(TiqConfig $conf[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $conf : TiqConfig
-
- Contains sensitive configuration data.
- $options : array<string|int, mixed> = []
-
- PDO class attributes.
Tags
clearCache()
Clear the query cache completely or for a specific query
public
clearCache([string|null $sql = null ][, mixed|null $args = null ]) : void
Parameters
- $sql : string|null = null
-
- The SQL query to clear, or null to clear all
- $args : mixed|null = null
-
- The query arguments (if clearing a specific query)
errorMessage()
Returns an error message that should be actionable. The information in the error message comes from the database.
public
errorMessage(PDOException $exception) : string
Parameters
- $exception : PDOException
Tags
Return values
stringrun()
Compresses a basic query down into one function.
public
run(string $sql[, mixed $args = null ][, bool $use_cache = false ]) : PDOStatement|false
Parameters
- $sql : string
-
- sql query.
- $args : mixed = null
-
- arguments to be used in the sql string.
- $use_cache : bool = false
-
- Allows caching of a query and args, if that same query is made again, we return the cached result
Tags
Return values
PDOStatement|falsegenerateCacheKey()
Generate a cache key for a query and its arguments
protected
generateCacheKey(string $sql, mixed $args) : string
Parameters
- $sql : string
-
- The SQL query
- $args : mixed
-
- The query arguments
Return values
string —- A unique cache key
parseConfig()
Breaks down the TiqConfig Object.
protected
parseConfig(TiqConfig $conf) : void
Parameters
- $conf : TiqConfig
-
- Contains sensitive configuration data.
profileQuery()
Profile a query for debugging purposes
protected
profileQuery(string $sql, float $execution_time, bool $cached) : void
Parameters
- $sql : string
-
- The SQL query
- $execution_time : float
-
- The execution time in seconds
- $cached : bool
-
- Whether this was a cache hit
parseException()
Initial version of hint parsing code.
private
parseException(PDOException $e) : array<string|int, string>
Parameters
- $e : PDOException