\apex\app\dbmysql

Handles all database communication between the software and the mySQL database. Please refer to the developer documentation for more details on methods within this class.

Summary

Methods
Properties
Constants
connect()
show_tables()
show_columns()
insert()
update()
delete()
get_row()
get_idrow()
get_column()
get_hash()
get_field()
query()
fetch_array()
fetch_assoc()
num_rows()
insert_id()
check_table()
begin_transaction()
commit()
rollback()
No public properties found
No constants found
get_connection()
No protected properties found
N/A
get_server_info()
format_sql()
get_placeholder()
$app
$db
$connections
$debug
$tables
$columns
$prepared
$raw_sql
$conn
N/A

Properties

$app

$app :

Type

$db

$db :

Type

$connections

$connections :

Type

$debug

$debug :

Type

$tables

$tables :

Type

$columns

$columns :

Type

$prepared

$prepared :

Type

$raw_sql

$raw_sql :

Type

$conn

$conn :

Type

Methods

connect()

connect(string  $dbname,string  $dbuser,string  $dbpass = '',string  $dbhost = 'localhost',integer  $dbport = 3306): 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\db\iterable  $args)

Updates the database via the 'UPDATE' command.

Parameters

\apex\app\db\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.

fetch_array()

fetch_array(mixed  $result)

The standard mysqli_fetch_array() function, except with error checking.

Parameters

mixed $result

the mysqli_result() object.

fetch_assoc()

fetch_assoc(mixed  $result)

The standard mysqli_fetch_assoc() function except with error checking.

Parameters

mixed $result

The mysqli_result object.

num_rows()

num_rows(mixed  $result)

Returns the number of rows affected by the previous SQL statement.

Parameters

mixed $result

The mysqli result.

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.

get_connection()

get_connection(string  $type = 'read')

Check database connection

Get database connection.

Checks to see whether we're connected to the mySQL database, and if so, if we're connected with the correct mySQL user depending on if it's a read / write connection.

Parameters

string $type

The type of connection we need (read or write).

get_server_info()

get_server_info(string  $type = 'read')

Get a database server credentials.

Parameters

string $type

The type of connection. Must be 'read' or 'write'

format_sql()

format_sql(mixed  $args)

Format SQL statement

Formats the SQL by sanitizing the values passed as additional parameters, and replacing the placeholders within the SQL statement with them.

Parameters

mixed $args

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

get_placeholder()

get_placeholder(string  $col_type)

Get placeholder based on column type

Parameters

string $col_type

The type of column