Methods summary
public
|
#
__construct( $namespace = null )
|
public
mixed
|
|
public
mixed
|
|
public
|
#
setSchemaManager( mixed $schemaManager )
|
public
PDO
|
#
connect( string $namespace = null )
Start database connection
Start database connection
Parameters
Returns
PDO or PDOException
|
public
string
|
#
getNamespace( string $namespace = null )
Return the current database namespace
if $namespace is not provided, $lc_defaultDbSource will be returned
if $lc_defaultDbSource is empty, default will be returned
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
string The database namespace
|
public
array
|
#
getConfig( string $namespace = null )
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
array The array of database configuration
|
public
string
|
#
getDriver( string $namespace = null )
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
string Database driver name
|
public
string
|
#
getHost( string $namespace = null )
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
string Database host name
|
public
string
|
#
getPort( string $namespace = null )
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
string Database port
|
public
string
|
#
getName( string $namespace = null )
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
string Database name
|
public
string
|
#
getUser( string $namespace = null )
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
string Database username
|
public
string
|
#
getPrefix( string $namespace = null )
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
string The table prefix
|
public
string
|
#
getCharset( string $namespace = null )
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
string Database charset
|
public
string
|
#
getCollation( string $namespace = null )
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
string Database collation
|
public
mixed
|
#
query( string $sql, array $args = array() )
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
mixed PDOStatement|boolean|string
|
public
string
|
#
getQueryStr( )
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
string Return the built and executed SQL string
|
public
array|false
|
#
fetchAssoc( PDOStatement $stmt )
Fetch a result row as an associative array
Fetch a result row as an associative array
Parameters
Returns
array|false An associative array that corresponds to the fetched row or NULL if there are no more rows.
|
public
array|false
|
#
fetchArray( PDOStatement $stmt )
Fetch a result row as an associative, a numeric array, or both
Fetch a result row as an associative, a numeric array, or both
Parameters
Returns
array|false 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
object|false
|
#
fetchObject( PDOStatement $stmt )
Returns the current row of a result set as an object
Returns the current row of a result set as an object
Parameters
Returns
object|false An object that corresponds to the fetched row or NULL if there are no more rows in result set.
|
public
array|boolean
|
#
fetchAll( string $sql, array $args = array(), integer $resultType = LC_FETCH_OBJECT )
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
array|boolean The result array of objects or associated arrays or index arrays.
If the result not found, return false.
|
public
object|boolean
|
#
fetchResult( string $sql, array $args = array() )
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
array(
':placeholder1' => $value1,
':placeholder2' => $value2
)
Returns
object|boolean The result object
|
public
mixed
|
#
fetchColumn( string $sql, array $args = array() )
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
array(
':placeholder1' => $value1,
':placeholder2' => $value2
)
Returns
mixed The value of the first field
|
public
integer
|
#
getNumRows( PDOStatement $stmt )
Gets the number of rows in a result
Gets the number of rows in a result
Parameters
Returns
integer Returns the number of rows in the result set.
|
public
integer|LucidFrame\Core\QueryBuilder
|
#
getCount( string $arg1, string|array $arg2 = null, string|null $arg3 = null )
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
array(
':placeholder1' => $value1,
':placeholder2' => $value2
)
- $arg3
The field alias if the first argument is table name
or the second argument is field name
Returns
|
public
integer
|
#
getInsertId( )
Returns the auto generated id used in the last query
Returns the auto generated id used in the last query
Returns
integer 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
string
|
#
getError( )
Returns a string description of the last error
Returns a string description of the last error
Returns
string
|
public
integer
|
#
getErrorCode( )
Returns the error code for the most recent query function call
Returns the error code for the most recent query function call
Returns
integer
|
public
|
#
close( )
Closes a previously opened database connection
Closes a previously opened database connection
|
public
string
|
#
getTable( string $table )
Get the full table name with prefix
Get the full table name with prefix
Parameters
- $table
- The table name with or without prefix
Returns
string The table name with prefix
|
public
boolean
|
#
hasSlug( string $table, boolean $useSlug = true )
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
boolean true or false
|
public
boolean
|
#
hasTimestamps( string $table )
Check the table has timestamp fields
Check the table has timestamp fields
Parameters
- $table
- The table name without prefix
Returns
boolean true or false
|
public
array
|
#
exp( string $field, mixed $value, string $exp = '' )
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
array The condition array, for example
array(
'value' => $value,
'exp >=' => $exp,
'field => $field
)
|