./Sources/Subs-Db-postgresql.php
- smf_db_initiate
- db_extend
- db_fix_prefix
- smf_db_replacement__callback
- smf_db_quote
- smf_db_query
- smf_db_affected_rows
- smf_db_insert_id
- smf_db_transaction
- smf_db_error
- smf_db_insert
- smf_db_select_db
- smf_db_version
- smf_db_error_backtrace
- smf_db_escape_wildcard_string
- smf_db_fetch_all
- smf_db_error_insert
- smf_db_custom_order
- smf_db_native_replace
- smf_db_cte_support
- smf_db_escape_string
- smf_db_connect_error
- smf_db_connect_errno
smf_db_initiate
function smf_db_initiate(string $db_server, string $db_name, string $db_user, string $db_passwd, string &$db_prefix, array $db_options = array()): ?resource
Maps the implementations in this file (smf_db_function_name) to the $smcFunc[‘db_function_name’] variable.
Type | Parameter | Description |
---|---|---|
string |
$db_server |
The database server |
string |
$db_name |
The name of the database |
string |
$db_user |
The database username |
string |
$db_passwd |
The database password |
string |
$db_prefix |
The table prefix |
array |
$db_options |
An array of database options |
db_extend
function db_extend(string $type = 'extra'): void
Extend the database functionality. It calls the respective file’s init to add the implementations in that file to $smcFunc array.
Type | Parameter | Description |
---|---|---|
string |
$type |
Indicates which additional file to load. (‘extra’, ‘packages’) |
db_fix_prefix
function db_fix_prefix(string &$db_prefix, string $db_name): void
Fix the database prefix if necessary.
Does nothing on PostgreSQL
Type | Parameter | Description |
---|---|---|
string |
$db_prefix |
The database prefix |
string |
$db_name |
The database name |
smf_db_replacement__callback
function smf_db_replacement__callback(array $matches): string
Callback for preg_replace_callback on the query.
It allows to replace on the fly a few pre-defined strings, for convenience (‘query_see_board’, ‘query_wanna_see_board’, etc), with their current values from $user_info. In addition, it performs checks and sanitization on the values sent to the database.
Type | Parameter | Description |
---|---|---|
array |
$matches |
The matches from preg_replace_callback |
smf_db_quote
function smf_db_quote(string $db_string, array $db_values, resource $connection = null): string
Just like the db_query, escape and quote a string, but not executing the query.
Type | Parameter | Description |
---|---|---|
string |
$db_string |
The database string |
array |
$db_values |
An array of values to be injected into the string |
resource |
$connection |
= null The connection to use (null to use $db_connection) |
smf_db_query
function smf_db_query(string $identifier, string $db_string, array $db_values = array(), resource $connection = null): resource|bool
Do a query. Takes care of errors too.
Special queries may need additional replacements to be appropriate for PostgreSQL.
Type | Parameter | Description |
---|---|---|
string |
$identifier |
An identifier. Only used in Postgres when we need to do things differently… |
string |
$db_string |
The database string |
array |
$db_values |
= array() The values to be inserted into the string |
resource |
$connection |
= null The connection to use (null to use $db_connection) |
smf_db_affected_rows
function smf_db_affected_rows(mixed $result = null): int
Returns the amount of affected rows for a query.
Type | Parameter | Description |
---|---|---|
mixed |
$result |
smf_db_insert_id
function smf_db_insert_id(string $table, string $field = null, resource $connection = null): int
Gets the ID of the most recently inserted row.
Type | Parameter | Description |
---|---|---|
string |
$table |
The table (only used for Postgres) |
string |
$field |
= null The specific field (not used here) |
resource |
$connection |
= null The connection (if null, $db_connection is used) (not used here) |
smf_db_transaction
function smf_db_transaction(string $type = 'commit', resource $connection = null): bool
Do a transaction.
Type | Parameter | Description |
---|---|---|
string |
$type |
The step to perform (i.e. ‘begin’, ‘commit’, ‘rollback’) |
resource |
$connection |
The connection to use (if null, $db_connection is used) |
smf_db_error
function smf_db_error(string $db_string, resource $connection = null): void
Database error! Backtrace, log, try to fix.
Type | Parameter | Description |
---|---|---|
string |
$db_string |
The DB string |
resource |
$connection |
The connection to use (if null, $db_connection is used) |
smf_db_insert
function smf_db_insert(string $method, string $table, array $columns, array $data, array $keys, int $returnmode = 0, resource $connection = null): mixed
Inserts data into a table
Type | Parameter | Description |
---|---|---|
string |
$method |
The insert method - can be ‘replace’, ‘ignore’ or ‘insert’ |
string |
$table |
The table we’re inserting the data into |
array |
$columns |
An array of the columns we’re inserting the data into. Should contain ‘column’ => ‘datatype’ pairs |
array |
$data |
The data to insert |
array |
$keys |
The keys for the table, needs to be not empty on replace mode |
int |
`` | returnmode 0 = nothing(default), 1 = last row id, 2 = all rows id as array; every mode runs only with method != ‘ignore’ |
resource |
$connection |
The connection to use (if null, $db_connection is used) |
smf_db_select_db
function smf_db_select_db(string $db_name, resource $db_connection): true
Dummy function really. Doesn’t do anything on PostgreSQL.
Type | Parameter | Description |
---|---|---|
string |
$db_name |
The database name |
resource |
$db_connection |
The database connection |
smf_db_version
function smf_db_version(): string
Get the current version.
smf_db_error_backtrace
function smf_db_error_backtrace(string $error_message, string $log_message = '', string|bool $error_type = false, string $file = null, int $line = null): void|array
This function tries to work out additional error information from a back trace.
Type | Parameter | Description |
---|---|---|
string |
$error_message |
The error message |
string |
$log_message |
The message to log |
string |bool |
$error_type |
What type of error this is |
string |
$file |
The file the error occurred in |
int |
$line |
What line of $file the code which generated the error is on |
smf_db_escape_wildcard_string
function smf_db_escape_wildcard_string(string $string, bool $translate_human_wildcards = false): string
Escape the LIKE wildcards so that they match the character and not the wildcard.
Type | Parameter | Description |
---|---|---|
string |
$string |
The string to escape |
bool |
$translate_human_wildcards |
If true, turns human readable wildcards into SQL wildcards. |
smf_db_fetch_all
function smf_db_fetch_all(resource $request): array
Fetches all rows from a result as an array
Type | Parameter | Description |
---|---|---|
resource |
$request |
A PostgreSQL result resource |
smf_db_error_insert
function smf_db_error_insert(array $error_array): void
Function to save errors in database in a safe way
Type | Parameter | Description |
---|---|---|
array |
`` | with keys in this order id_member, log_time, ip, url, message, session, error_type, file, line |
smf_db_custom_order
function smf_db_custom_order(string $field, array $array_values, bool $desc = false): string
Function which constructs an optimize custom order string as an improved alternative to find_in_set()
Type | Parameter | Description |
---|---|---|
string |
$field |
name |
array |
$array_values |
Field values sequenced in array via order priority. Must cast to int. |
bool |
$desc |
default false |
smf_db_native_replace
function smf_db_native_replace(): bool
Function which return the information if the database supports native replace inserts
smf_db_cte_support
function smf_db_cte_support(): bool
Function which return the information if the database supports cte with recursive
smf_db_escape_string
function smf_db_escape_string(string $string, resource $connection = null): string
Function which return the escaped string
Type | Parameter | Description |
---|---|---|
string |
`` | the unescaped text |
resource |
$connection |
= null The connection to use (null to use $db_connection) |
smf_db_connect_error
function smf_db_connect_error(): string
Function to return the pg connection error message.
Emulating mysqli_connect_error. Since pg_connect() doesn’t feed info to pg_last_error, we need to use a try/catch & preserve error info.
smf_db_connect_errno
function smf_db_connect_errno(): string
Function to return the pg connection error number.
Emulating mysqli_connect_errno. Since pg_connect() doesn’t feed info to pg_last_error, we need to use a try/catch & preserve error info.