DB Constructor
Connects to the server and selects a database.
Parameters:
|
array |
$params: |
An array of parameters. Manadatory: - 'user': username to connect with
- 'password': password to connect with
OR - 'handle': a MySQL Database handle (from a previous mysql_connect())
Optional: - 'name': the name of the default database, see DB::select()
- 'host': host of the database; Default: 'localhost'
- 'show_errors': Display SQL errors? (true/false); Default: don't change member default ($show_errors)
- 'halt_on_error': Halt on error? (true/false); Default: don't change member default ($halt_on_error)
- 'table_options': sets $table_options
- 'use_transactions': sets $use_transactions
- 'aliases': Aliases for tables (array( alias => table name )); Default: no aliases.
- 'new_link': create a new link to the DB, even if there was a mysql_connect() with
the same params before. (requires PHP 4.2)
- 'client_flags': optional settings like compression or SSL encryption. See http://www.php.net/manual/en/ref.mysql.php#mysql.client-flags.
(requires PHP 4.3)
|
BEGIN A TRANSCATION
Note: By default, MySQL runs with autocommit mode enabled. This means that as soon as you execute a statement that updates (modifies) a table, MySQL stores the update on disk. Once you execute a BEGIN, the updates are "pending" until you execute a COMMIT or a DB:rollback()
Note 2: standard syntax would be START TRANSACTION but it's not supported by older MySQL versions whereas BEGIN is...
Note 3: The default isolation level is REPEATABLE READ.
Commit current transaction
string compString(
mixed
$val
)
|
|
Returns the appropriate string to compare $val in a WHERE clause.
Parameters:
|
mixed |
$val: |
Value to create a "compare-String" for |
API Tags:
| Return: | Either 'IS NULL', 'IN ("a", "b", "c")' or " = 'a'". |
string debug_get_rows_table(
$max_lines, [
$break_at_comma = false]
)
|
|
Get a table (or "<p>No Results.</p>") for the SELECT query results.
Parameters:
|
|
$max_lines: |
|
|
|
$break_at_comma: |
|
API Tags:
| Return: | HTML table or "No Results" if the |
Displays all queries that have been executed
Format a string correctly for safe insert under all PHP conditions
Parameters:
Kill cached query results
void format_query(
$sql
)
|
|
Parameters:
array get_assoc(
[
$query = NULL], [
$title = '']
)
|
|
Function to get the second column from the cached result indexed by the first column
Parameters:
API Tags:
array get_col(
[
$query = NULL], [
$x = 0], [
$title = '']
)
|
|
Function to get 1 column from the cached result set based in X index see docs for usage and info
Parameters:
void get_col_info(
[
$info_type = 'name'], [
$col_offset = -1]
)
|
|
Function to get column meta data info pertaining to the last query see docs for more info and usage
Note: DB::log_queries must be enabled for this to work.
Parameters:
string get_list(
[string|NULL
$query = NULL], [integer
$x = 0], [
$title = '']
)
|
|
Get a column as comma-separated list.
Parameters:
|
string|NULL |
$query: |
Query to execute |
|
integer |
$x: |
Column of the result set |
|
|
$title: |
|
array get_results(
[
$query = NULL], [
$output = OBJECT], [
$title = '']
)
|
|
Return the the query as a result set - see docs for more details
Parameters:
array|object get_row(
[
$query = NULL], [
$output = OBJECT], [
$y = 0], [
$title = '']
)
|
|
Get one row from the DB - see docs for more detail
Parameters:
|
|
$query: |
|
|
|
$output: |
|
|
|
$y: |
|
|
|
$title: |
|
mixed get_var(
[
$query = NULL], [
$x = 0], [
$y = 0], [
$title = '']
)
|
|
Get one variable from the DB - see docs for more detail
Note: To be sure that you received NULL from the DB and not "no rows" check for $num_rows.
Parameters:
API Tags:
| Return: | NULL if not found, the value otherwise (which may also be NULL). |
Parameters:
API Tags:
| Return: | Return the given value or 'NULL', if it's === NULL. |
void print_error(
[
$str = ''], [
$query_title = '']
)
|
|
Print SQL/DB error.
TODO: bloated: it probably doesn't make sense to display errors if we don't stop. Any use case?
Parameters:
mixed query(
string
$query, [string
$title = '']
)
|
|
Basic Query
Parameters:
|
string |
$query: |
SQL query |
|
string |
$title: |
title for debugging |
API Tags:
| Return: | # of rows affected or false if error |
Quote a value, either in single quotes (and escaped) or if it's NULL as 'NULL'.
Parameters:
API Tags:
| Return: | Quoted (and escaped) value or 'NULL'. |
Rollback current transaction
Select a DB (if another one needs to be selected)
Parameters:
boolean set_connection_charset(
string
$charset, [boolean
$use_map = false]
)
|
|
Set the charset of the connection.
WARNING: this will fail on MySQL 3.23
Parameters:
|
string |
$charset: |
Charset |
|
boolean |
$use_map: |
Use the "regular charset => mysql charset map"? |
API Tags:
| Return: | true on success, false on failure |
| Staticvar: | array $mysql_charset_map: "regular charset => mysql charset map" |
void week(
string
$date, integer
$startofweek
)
|
|
Returns the correct WEEK() function to get the week number for the given date.
Parameters:
|
string |
$date: |
will be used as is |
|
integer |
$startofweek: |
0 for sunday, 1 for monday |
Information Tags: