class SchemaDB

The SchemaDB class contains static methods that allow you to manipulate the database. It is used to create and modify tables and indexes in the database.

Methods

static array
getTables()

Return the tables on the database.

static bool
checkTableStructure(string $tableName)

Create or update the structure of the table.

static bool
tableExists(string $tableName)

Return true if $tableName exists in database

static array
updateFields(string $tableName, array $fieldsList)

Update fields for tablename.

static string
modifyFields(string $tableName, array $fieldsList)

Modify (add or change) fields for tablename.

static string
assignFields(array $fieldsList, string $fieldOperation = '')

Convert an array of fields into a string to be added to an SQL command, CREATE TABLE or ALTER TABLE.

static string
quoteTableName(string $tableName, bool $usePrefix = true)

Returns the name of the table in quotes.

static array
createFields(string $tableName, array $fieldsList)

Build the SQL statement to create the fields in the table.

static array
createIndex(string $tableName, string $indexName, array $indexData)

Create the SQL statements for the construction of one index.

static array
createPrimaryIndex(string $tableName, array $indexData, bool $autoincrement, bool $exists = false)

Creates index for primary key of tablename.

static string
quoteFieldName(string $fieldName)

Returns the name of the field in quotes.

static array
createConstraint(string $tableName, array $indexData, bool $exists = false)

Creates a constraint for tablename.

static array
createStandardIndex(string $tableName, array $indexData, bool $exists = false)

Creates a standard index for tablename.

static array
createUniqueIndex(string $tableName, array $indexData, bool $exists = false)

Creates a unique index for the tablename.

static array
createTableView(string $tableName)

Create a tableView

Details

at line 26
static array getTables()

Return the tables on the database.

Return Value

array

at line 45
static bool checkTableStructure(string $tableName)

Create or update the structure of the table.

It does not destroy fields of the structure, it only creates, adds or modifies the existing ones. NOTE: It could happen that when modifying the structure of a field, information could be lost.

Parameters

string $tableName

Return Value

bool

at line 88
static bool tableExists(string $tableName)

Return true if $tableName exists in database

Parameters

string $tableName

Return Value

bool

at line 102
static protected array updateFields(string $tableName, array $fieldsList)

Update fields for tablename.

Parameters

string $tableName
array $fieldsList

Return Value

array

at line 119
static private string modifyFields(string $tableName, array $fieldsList)

Modify (add or change) fields for tablename.

Parameters

string $tableName
array $fieldsList

Return Value

string

at line 147
static protected string assignFields(array $fieldsList, string $fieldOperation = '')

Convert an array of fields into a string to be added to an SQL command, CREATE TABLE or ALTER TABLE.

You can add a prefix field operation (usually ADD or MODIFY) that will be added at begin of each field.

Parameters

array $fieldsList
string $fieldOperation (usually ADD, MODIFY or empty string)

Return Value

string

at line 167
static private string quoteTableName(string $tableName, bool $usePrefix = true)

Returns the name of the table in quotes.

Parameters

string $tableName
bool $usePrefix

Return Value

string

at line 181
static protected array createFields(string $tableName, array $fieldsList)

Build the SQL statement to create the fields in the table.

It can also create the primary key if the auto_increment attribute is defined.

Parameters

string $tableName
array $fieldsList

Return Value

array

at line 206
static protected array createIndex(string $tableName, string $indexName, array $indexData)

Create the SQL statements for the construction of one index.

In the case of the primary index, it is not necessary if it is auto_increment.

TODO:

Moreover, it should not be defined if it is auto_increment because it would generate an error when it already exists.

Parameters

string $tableName
string $indexName
array $indexData

Return Value

array

at line 248
static protected array createPrimaryIndex(string $tableName, array $indexData, bool $autoincrement, bool $exists = false)

Creates index for primary key of tablename.

Parameters

string $tableName
array $indexData
bool $autoincrement
bool $exists

Return Value

array

at line 277
static private string quoteFieldName(string $fieldName)

Returns the name of the field in quotes.

Parameters

string $fieldName

Return Value

string

at line 291
static protected array createConstraint(string $tableName, array $indexData, bool $exists = false)

Creates a constraint for tablename.

Parameters

string $tableName
array $indexData
bool $exists

Return Value

array

at line 336
static protected array createStandardIndex(string $tableName, array $indexData, bool $exists = false)

Creates a standard index for tablename.

Parameters

string $tableName
array $indexData
bool $exists

Return Value

array

at line 361
static protected array createUniqueIndex(string $tableName, array $indexData, bool $exists = false)

Creates a unique index for the tablename.

Parameters

string $tableName
array $indexData
bool $exists

Return Value

array

at line 388
static protected array createTableView(string $tableName)

Create a tableView

Parameters

string $tableName

Return Value

array