Methods |
public
|
__construct($namespace = null)
|
#
|
public
|
getConnection(): mixed
|
#
|
public
|
getSchemaManager(): mixed
|
#
|
public
|
setSchemaManager(mixed $schemaManager)
|
#
|
public
|
connect(string $namespace = null): PDO
Start database connection
Start database connection
Returns
|
#
|
public
|
getNamespace(string $namespace = null): string
Return the current database namespace
if $namespace is not provided, $lc_defaultDbSource will be returned
if $lc…
Return the current database namespace
if $namespace is not provided, $lc_defaultDbSource will be returned
if $lc_defaultDbSource is empty, default will be returned
Parameters
$namespace |
The given namespace
|
Returns
|
#
|
public
|
getConfig(string $namespace = null): array
Return the database configuration of the given namespace
Return the database configuration of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
The array of database configuration
|
#
|
public
|
getDriver(string $namespace = null): string
Return the database driver of the given namespace
Return the database driver of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getHost(string $namespace = null): string
Return the database host name of the given namespace
Return the database host name of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getPort(string $namespace = null): string
Return the database port of the given namespace
Return the database port of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getName(string $namespace = null): string
Return the database name of the given namespace
Return the database name of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getUser(string $namespace = null): string
Return the database user name of the given namespace
Return the database user name of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getPrefix(string $namespace = null): string
Return the database table prefix of the given namespace
Return the database table prefix of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getCharset(string $namespace = null): string
Return the database charset of the given namespace
Return the database charset of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
getCollation(string $namespace = null): string
Return the database collation of the given namespace
Return the database collation of the given namespace
Parameters
$namespace |
Namespace of the configuration to read from
|
Returns
|
#
|
public
|
query(string $sql, array $args = []): mixed
Perform a query on the database
Perform a query on the database
Parameters
$sql |
SQL query string
|
$args |
Array of placeholders and their values
array(
':placeholder1' => $value1,
':placeholder2' => $value2
)
The prefix colon ":" for placeholder is optional
|
Returns
PDOStatement|boolean|string
|
#
|
public
|
getQueryStr(): string
Get the last executed SQL string or one of the executed SQL strings by providing the index
Get the last executed SQL string or one of the executed SQL strings by providing the index
Returns
Return the built and executed SQL string
|
#
|
public
|
fetchAssoc(PDOStatement $stmt): array|false
Fetch a result row as an associative array
Fetch a result row as an associative array
Returns
An associative array that corresponds to the fetched row or NULL if there are no more rows.
|
#
|
public
|
fetchArray(PDOStatement $stmt): array|false
Fetch a result row as an associative, a numeric array, or both
Fetch a result row as an associative, a numeric array, or both
Returns
An array that corresponds to the fetched row or
NULL if there are no more rows for the result set represented by the result parameter.
|
#
|
public
|
fetchObject(PDOStatement $stmt): object|false
Returns the current row of a result set as an object
Returns the current row of a result set as an object
Returns
An object that corresponds to the fetched row or NULL if there are no more rows in result set.
|
#
|
public
|
fetchAll(string $sql, array $args = [], int $resultType = LC_FETCH_OBJECT): array|boolean
Perform a query on the database and return the array of all results
Perform a query on the database and return the array of all results
Parameters
$sql |
The SQL query string
|
$args |
The array of placeholders and their values
|
$resultType |
The optional constant indicating what type of array should be produced.
The possible values for this parameter are the constants
LC_FETCH_OBJECT, LC_FETCH_ASSOC, or LC_FETCH_ARRAY.
Default to LC_FETCH_OBJECT.
|
Returns
The result array of objects or associated arrays or index arrays.
If the result not found, return false.
|
#
|
public
|
fetchResult(string $sql, array $args = []): object|boolean
Perform a query on the database and return the first result row as object
Perform a query on the database and return the first result row as object
It adds the LIMIT 1 clause if the query has no record limit
This is useful for one-row fetching. No need explicit db_query() call as this invokes it internally.
Parameters
$sql |
The SQL query string
|
$args |
The array of placeholders and their values
|
Returns
|
#
|
public
|
fetchColumn(string $sql, array $args = []): mixed
Perform a query on the database and return the first field value only.
Perform a query on the database and return the first field value only.
It adds the LIMIT 1 clause if the query has no record limit
This will be useful for COUNT() , MAX() , MIN() queries
Parameters
$sql |
The SQL query string
|
$args |
The array of placeholders and their values
|
Returns
The value of the first field
|
#
|
public
|
getNumRows(PDOStatement $stmt): int
Gets the number of rows in a result
Gets the number of rows in a result
Returns
Returns the number of rows in the result set.
|
#
|
public
|
getCount(string $arg1, string|array $arg2 = null, string|null $arg3 = null): int|QueryBuilder
Perform a count query on the database and return the count
Perform a count query on the database and return the count
Parameters
$arg1 |
The SQL query string or table name
|
$arg2 |
The field name to count on
or the array of placeholders and their values if the first argument is SQL
|
$arg3 |
The field alias if the first argument is table name
or the second argument is field name
|
Returns
|
#
|
public
|
getInsertId(): int
Returns the auto generated id used in the last query
Returns the auto generated id used in the last query
Returns
The value of the AUTO_INCREMENT field that was updated by the previous query;
0 if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.
|
#
|
public
|
getError(): string
Returns a string description of the last error
Returns a string description of the last error
|
#
|
public
|
getErrorCode(): int
Returns the error code for the most recent query function call
Returns the error code for the most recent query function call
|
#
|
public
|
close(): void
Closes a previously opened database connection
Closes a previously opened database connection
|
#
|
public
|
getTable(string $table): string
Get the full table name with prefix
Get the full table name with prefix
Parameters
$table |
The table name with or without prefix
|
Returns
The table name with prefix
|
#
|
public
|
hasSlug(string $table, boolean $useSlug = true): boolean
Check the table has slug field
Check the table has slug field
Parameters
$table |
The table name without prefix
|
$useSlug |
True to include the slug field or False to not exclude it
|
Returns
|
#
|
public
|
hasTimestamps(string $table): boolean
Check the table has timestamp fields
Check the table has timestamp fields
Parameters
$table |
The table name without prefix
|
Returns
|
#
|
public
|
exp(string $field, mixed $value, string $exp = ''): array
Build the SQL expression like SUM, MAX, AVG, etc
Build the SQL expression like SUM, MAX, AVG, etc
Parameters
$field |
The field name
|
$value |
The value for the field
|
$exp |
The SQL expression
|
Returns
The condition array, for example
|
#
|