Apexdb:: Service -- Back-End Database (mySQL)Class: apex\app\db\mysqlThis service provides access to the back-end database, which by default is mySQL, although other database engines such as PostgreSQL or Oracle can be easily integrated. As with all services, the methods can be accessed statically providing easy and efficient access. Example
SQL PlaceholdersPlaceholders are fully supported to properly sanitize all SQL queries, helping prevent SQL injection attacks. All placeholders begin with the % sign, followed by one or two characters. For example:
In the above example, the value of the status (%s) column must be a string, and the value of the group_id (%i) column must be an integer. The actual values are then passed as additional parameters to the function, and are properly checked and sanitized before being sent to the mySQL database engine. The below table lists all available placeholders: Placeholder | Description ------------- |------------- %s | String %i | Integer, no decimal points %d | Decimal %b | Boolean, only allowed values are 1 / 0 %e | E-mail address %url | URL %ds | Date stamp, must be formatted in YYYY-MM-DD %ts | Timestampe, must be formatted in HH:II:SS %ls | For the LIKE operand. Sanitizes the value, and surrounds it with '%' characters. For example, the value "john" becomes "'%john%'" db::query(string $sql, array $args)Description: Performs any SQL statement against the database, but is generally used for SELECT statements,
and simply returns the result of the Example
db::insert(string $table_name, array $values)Description: Inserts a new row into the specified database table. Parameters
** Example**
db::update(string $table_name, array $values, string $where_sql, array $args)Description: Updates one or more rows within the provided table name of the database. Parameters
** Example**
db::delete(string $table_name, string $where_sql, array $args)Description: Deletes rows from the specified table. Parameters
Example
array db::get_row(string $sql, array $args)</apiDescription: Get the first row found using the given SQL query, and returns an associative array of the values. Returns false if no row exists. Example
`array db::get_idrow(string $table_name in $id_number)Description: Similiar to the
Example
array db::get_column(string $sql, array $args)Description: Returns a one-dimensional array of one specific column within a database table. Example
array db::get_hash(string $sql, array $args)**Description:* Returns an associative array of the two columns defined within the SQL statement. Useful for creating a quick key-value pair from a database table. Example
string db::get_field(string $sql, array $args)Description: Returns the first column from the first row of the resulting SQL statement. Useful for getting a single field from a single row from the database. Example
int db::insert_id()Description: Simply returns the ID# of the last row inserted into a table with an id column that auto increments. array db::show_tables()Description: Returns a one-dimensional array of all tables within the database. array db::show_columns(string $table_name, bool $include_types = false)** Description:** Returns an one-dimenational array of all columns within the given table provided. If
db::begin_transaction()Description: Begins a new database transaction. db::commit()Description: Submits the currently open database transaction. db::rollback()Description: Rollsback the currently open database transaction. Need a Professional?Need development work by the creator of Apex? E-mail matt.dizak@gmail.com for a free consultation. Recent NewsMailing ListSubscribe to the low traffic mailing list to stay updated on Apex. ![]() |
Apex v1.5.4 Released!
Added .env file, Remote Access Client, finalized PostgreSQL, and more...