All database functions
Just run composer install [package_name]
After that all these functions should be available in every PHP file (via composer's autoloader)
@var \PDO $dbh *
function db_connect()
Internal function to prepare and execute query (returns $sth)
function db_prepare_exec($query, $args, &$rv = NULL)
Executes a insert/update query on database Returns last_insert_id if insert, row count otherwise
function db_exec($query, ...$args)
Executes a select query on database
function db_query($query, ...$args)
Executes a query on database and caches the results
function db_query_cached(int $expiry, string $query, ...$args)
Executes a query on database, caches the results (in file) and returns the first row
function db_query_cached_single(int $expiry, string $query, ...$args)
Executes a select query on database and returns the first rows
function db_query_single($query, ...$args)
Executes a select query on database and returns the first column of first row SELECT user_id from users limit 1; // returns user_id of first row
function db_query_value($query, ...$args)
Executes a select query on database and returns the first column of all rows as array SELECT user_id from users where name = 'san'; // returns all user_id where name = 'san'
function db_query_values($query, ...$args)
Returns the table schema
function db_table_schema($table)
Returns the list of tables in a database
function db_list_tables($cached = TRUE)
Finds a record
function db_find($table, $matches = [], $limit = 1)
Finds a record using cache (local file system)
function db_find_cached(int $expiry, $table, $matches = [], $limit = 1)
Finds a record using the cache
table in current database
function db_find_cached_table($name, $value = NULL, $expires = '+1 day')
Inserts a row into a table optionally filling out fields like created_at, updated_at, etc
function db_insert($table, array $values, $magic = FALSE, $insert_ignore = FALSE)
Updates matching rows optionally filling out fields like updated_at, etc
function db_update($table, array $matches, array $updates, $magic = FALSE, $update_ignore = FALSE, $limit = 1)
Returns the count of matching rows
function db_count($table, array $matches)
Delets matching rows
function db_delete($table, array $matches, $limit = 1)
Easy way to do CRUD operation on database
function db_crud($op, $table, $match, $updates = NULL, $failsafe = ['id', 'user_id'], $json_fields = [])
Quotes a string using PDO
function db_quote($str)