\apex\app\interfacesDBInterface

Database interface

Summary

Methods
Constants
connect()
show_tables()
show_columns()
insert()
update()
delete()
get_row()
get_idrow()
get_column()
get_hash()
get_field()
query()
insert_id()
check_table()
begin_transaction()
commit()
rollback()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

connect()

connect(string  $dbname, string  $dbuser, string  $dbpass, string  $dbhost, integer  $dbport) : object

Initiates a connection to the database, and returns the resulting connection.

Parameters

string $dbname

The database name

string $dbuser

The database username

string $dbpass

Optional database password

string $dbhost

optional database host, defaults to 'localhost'

integer $dbport

Optional database port, defaults to 3306

Returns

object —

The resulting database connection

show_tables()

show_tables() 

Executes the 'SHOW TABLES' command, and returns a one-dimensional array of all tables within the database.

show_columns()

show_columns(string  $table_name, boolean  $include_types = false) : array

Returns an array of all columns within the given table name.

Parameters

string $table_name

The name of the table to retrieve column names from.

boolean $include_types

Whether or not to include the types of columns as the value of array

Returns

array —

One-dimensional array of column names.

insert()

insert(mixed  $args) 

Inserts a new record into the database.

Parameters

mixed $args

First element is the table name, second an associative array of values to insert.

update()

update(\apex\app\interfaces\iterable  $args) 

Updates the database via the 'UPDATE' command.

Parameters

\apex\app\interfaces\iterable $args

First element is table name, second is associative array of update volumns / values, third is WHERE SQL, and others are placeholders values for where sql.

delete()

delete(mixed  $args) 

Delete one or more rows from a table via the DELETE sataement.

Parameters

mixed $args

First element is the table name, second is the WHERE clause, and third and others are values of placeholders.

get_row()

get_row(mixed  $args) : array

Gets a single row from the database, and if the SQL statement matches more than one row, only returns the first row.

Parameters

mixed $args

First element is the SQL statement, other elements are values of the place holders.

Returns

array —

Array of key-value pairs of the one row retrieved. False if no row found.

get_idrow()

get_idrow(string  $table_name, string  $id_number) : array

A short-hand version of the above 'get_row()' method, and used if you're retrieving a specific row by the 'id' column.

Parameters

string $table_name

The table name to retrive the row from.

string $id_number

The value of the 'id' column to retrieve.

Returns

array —

Array containing key-value pairs of the row retrieved.

get_column()

get_column(mixed  $args) : array

Retrieves a single column from a table, and returns a one-dimensional array of the values.

Parameters

mixed $args

First element is the SQL statement, other elements are values of the place holders.

Returns

array —

One-dimensional array containing the values of the column.

get_hash()

get_hash(mixed  $args) : array

Get two column hash

Retrieves two columns from a database (ie. 'id', and some other column), and returns an array of key-value pairs of the results.

Parameters

mixed $args

First element is the SQL statement, other elements are values of the place holders.

Returns

array —

Array of key-value pairs of the results.

get_field()

get_field(mixed  $args) : string

Gets a single column from a single row, and returns the resulting scalar variable.

Parameters

mixed $args

First element is the SQL statement, other elements are values of the place holders.

Returns

string —

The value of the column from the first row. Returns false if no rows matched.

query()

query(mixed  $args) : mixed

Executes any SQL statement against the database, and returns the result.

Parameters

mixed $args

First element is the SQL statement, other elements are values of the place holders.

Returns

mixed —

The result of the query.

insert_id()

insert_id() 

Returns the ID# of the previous INSERT statement.

check_table()

check_table(string  $table_name) : boolean

Checks to see whether or not a table exists within the database.

Parameters

string $table_name

The table name to check.

Returns

boolean —

WHether or not the table exists in the database.

begin_transaction()

begin_transaction() 

Begin transaction

Begins a new transaction within the database, meaning no further SQL queries will be executed against the database until a COMMIT is executed.

commit()

commit() 

Commit transaction

Commits a transaction, meaning any SQL queries that were executed after the transaction will now be written to the database.

rollback()

rollback() 

Rollback transaction

Performs a rollback on the previously started transaction, meaning none of the SQL statements executed since the transaction began will be applied to the database.