abstract class vB_Database_Alter

Database Modification Class

This class allows an abstracted method for altering database structure without throwing database errors willy nilly

Properties

boolean $init Whether a table has been initialized for altering.
integer $error_no Number of the latest error from the database. 0 if no error.
string $error_desc Description of the latest error from the database.
string $sql The text of the last query that has been run. Helpful for debugging.
array $table_index_data Array of table index data
array $table_status_data Array of table status data
array $table_field_data Array of table field data
string $table_name Name of the table being altered
object $db Database object
$tag

Methods

__construct(vB_Database $db)

Constructor - checks that the database object has been passed correctly.

bool
fetch_table_info(string $tablename = '')

Public Populates the $table_index_data, $table_status_data and $table_field_data arrays with all relevant information that is obtainable about this database table. Leave $tablename blank to use the table used in the previous call to this functions. The arrays are used by the private and public functions to perform their work. Nothing can be done to a table until this function is invoked.

string
fetch_error()

Public Returns a text value that relates to the error condition, useable to prepare human readable error phrase varname strings

string
fetch_error_message()

Public Returns error description, set manually or by database error handler

string
fetch_table_type()

Public Returns the table type, e.g. ISAM, MYISAM, InnoDB

bool
drop_index(string $fieldname)

Public Drops an index

bool
add_index(string $fieldname, mixed $fields, string $type = '', bool $overwrite = false)

Public Creates an index. Can be single or multi-column index, normal, unique or fulltext

bool
add_field(array $fields, bool $overwrite = false)

Public Adds field. Can be single fields, or multiple fields. If a field already exists, false will be returned so to silently fail on duplicate fields you would want to call this multiple times, creating a field one at a time.

bool
drop_field($fields)

Public Drops field. Can be single fields, or multiple fields. If a field doesn't exist, false will be returned so to silently fail on missing fields you would want to call this multiple times, dropping a field one at a time.

bool
query(string $query, bool $escape = false)

Public Direct write query to the database with error trapping. Useful when a collision isn't important

void
set_error(integer $errno = 0, string $desc = '')

Private Set the $error_no and $error_desc variables

void
init_table_info()

Private Verifies that fetch_table_info() has been called for a valid table and sets current error condition to none

Details

at line 111
__construct(vB_Database $db)

Constructor - checks that the database object has been passed correctly.

Parameters

vB_Database $db The vB_Database object ($db)

at line 134
bool fetch_table_info(string $tablename = '')

Public Populates the $table_index_data, $table_status_data and $table_field_data arrays with all relevant information that is obtainable about this database table. Leave $tablename blank to use the table used in the previous call to this functions. The arrays are used by the private and public functions to perform their work. Nothing can be done to a table until this function is invoked.

Parameters

string $tablename Name of table

Return Value

bool

at line 167
string fetch_error()

Public Returns a text value that relates to the error condition, useable to prepare human readable error phrase varname strings

Return Value

string

at line 197
string fetch_error_message()

Public Returns error description, set manually or by database error handler

Return Value

string

at line 210
string fetch_table_type()

Public Returns the table type, e.g. ISAM, MYISAM, InnoDB

Return Value

string

at line 223
bool drop_index(string $fieldname)

Public Drops an index

Parameters

string $fieldname Name of index to drop

Return Value

bool

at line 236
bool add_index(string $fieldname, mixed $fields, string $type = '', bool $overwrite = false)

Public Creates an index. Can be single or multi-column index, normal, unique or fulltext

Parameters

string $fieldname Name of index to drop
mixed $fields Name of field to index. Create a multi field index by sending an array of field names
string $type Default is normal. Valid options are 'FULLTEXT' and 'UNIQUE'
bool $overwrite true = delete an existing index, then add. false = return false if index of same name already exists unless it matches exactly

Return Value

bool

at line 248
bool add_field(array $fields, bool $overwrite = false)

Public Adds field. Can be single fields, or multiple fields. If a field already exists, false will be returned so to silently fail on duplicate fields you would want to call this multiple times, creating a field one at a time.

Parameters

array $fields Definition of field to index. Create multiple fields by sending an array of definitions but see note above.
bool $overwrite true = delete an existing field of same name, then create. false = return false if a field of same name already exists

Return Value

bool

at line 260
bool drop_field($fields)

Public Drops field. Can be single fields, or multiple fields. If a field doesn't exist, false will be returned so to silently fail on missing fields you would want to call this multiple times, dropping a field one at a time.

Parameters

$fields

Return Value

bool

at line 271
bool query(string $query, bool $escape = false)

Public Direct write query to the database with error trapping. Useful when a collision isn't important

Parameters

string $query Direct query string to perform
bool $escape true: escape_string $query false: use as-is

Return Value

bool

at line 282
void set_error(integer $errno = 0, string $desc = '')

Private Set the $error_no and $error_desc variables

Parameters

integer $errno Errorcode - use values defined at top of class file
string $desc Description of error. Manually set or returned by database error handler

Return Value

void

at line 297
void init_table_info()

Private Verifies that fetch_table_info() has been called for a valid table and sets current error condition to none

.. in other words verify that fetchTableInfo returns true before proceeding on

Return Value

void