$_adapter
$_adapter : \Horde_Db_Adapter_Base
A Horde_Db_Adapter instance.
Class for MySQL-specific managing of database schemes and handling of SQL dialects and quoting.
$_adapter : \Horde_Db_Adapter_Base
A Horde_Db_Adapter instance.
__construct(\Horde_Db_Adapter_Base $adapter)
Constructor.
\Horde_Db_Adapter_Base | $adapter | A Horde_Db_Adapter instance. |
setAdapter(\Horde_Db_Adapter $adapter)
Setter for a Horde_Db_Adapter instance.
\Horde_Db_Adapter | $adapter | A Horde_Db_Adapter instance. |
makeColumn(string $name, string $default, string $sqlType = null, boolean $null = true) : \Horde_Db_Adapter_Mysql_Column
Factory for Column objects.
string | $name | The column's name, such as "supplier_id" in "supplier_id int(11)". |
string | $default | The type-casted default value, such as "new" in "sales_stage varchar(20) default 'new'". |
string | $sqlType | Used to extract the column's type, length and signed status, if necessary. For example "varchar" and "60" in "company_name varchar(60)" or "unsigned => true" in "int(10) UNSIGNED". |
boolean | $null | Whether this column allows NULL values. |
A column object.
makeColumnDefinition( $base, $name, $type, $limit = null, $precision = null, $scale = null, $unsigned = null, $default = null, $null = null, $autoincrement = null) : \Horde_Db_Adapter_Base_ColumnDefinition
Factory for ColumnDefinition objects.
$base | ||
$name | ||
$type | ||
$limit | ||
$precision | ||
$scale | ||
$unsigned | ||
$default | ||
$null | ||
$autoincrement |
A column definition object.
makeIndex(string $table, string $name, boolean $primary, boolean $unique, array $columns) : \Horde_Db_Adapter_Base_Index
Factory for Index objects.
string | $table | The table the index is on. |
string | $name | The index's name. |
boolean | $primary | Is this a primary key? |
boolean | $unique | Is this a unique index? |
array | $columns | The columns this index covers. |
An index object.
makeTable( $name, $primaryKey, $columns, $indexes) : \Horde_Db_Adapter_Base_Table
Factory for Table objects.
$name | ||
$primaryKey | ||
$columns | ||
$indexes |
A table object.
makeTableDefinition( $name, $base, $options = array()) : \Horde_Db_Adapter_Base_TableDefinition
Factory for TableDefinition objects.
$name | ||
$base | ||
$options |
A table definition object.
quote(mixed $value, object $column = null) : string
Quotes the column value to help prevent SQL injection attacks.
This method makes educated guesses on the scalar type based on the passed value. Make sure to correctly cast the value and/or pass the $column parameter to get the best results.
mixed | $value | The scalar value to quote, a Horde_Db_Value, Horde_Date, or DateTime instance, or an object implementing quotedId(). |
object | $column | An object implementing getType(). |
The correctly quoted value.
table(string $tableName, string $name = null) : \Horde_Db_Adapter_Base_Table
Returns a Horde_Db_Adapter_Base_Table object for a table.
string | $tableName | A table name. |
string | $name | (can be removed?) |
A table object.
primaryKey(string $tableName, string $name = null) : \Horde_Db_Adapter_Base_Index
Returns a table's primary key.
string | $tableName | A table name. |
string | $name | (can be removed?) |
The primary key index object.
column(string $tableName, string $columnName) : \Horde_Db_Adapter_Base_Column
Returns a table column.
string | $tableName | A table name. |
string | $columnName | A column name. |
if column not found.
A column object.
createTable(string $name, array $options = array()) : \Horde_Db_Adapter_Base_TableDefinition
Creates a new table.
The $options hash can include the following keys:
Examples:
// Add a backend specific option to the generated SQL (MySQL)
$schema->createTable('suppliers', array('options' => 'ENGINE=InnoDB DEFAULT CHARSET=utf8')));
generates:
CREATE TABLE suppliers ( id int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=InnoDB DEFAULT CHARSET=utf8
// Rename the primary key column
$table = $schema->createTable('objects', array('autoincrementKey' => 'guid'));
$table->column('name', 'string', array('limit' => 80));
$table->end();
generates:
CREATE TABLE objects ( guid int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(80) )
// Do not add a primary key column, use fluent interface, use type
// method.
$schema->createTable('categories_suppliers', array('autoincrementKey' => false))
->column('category_id', 'integer')
->integer('supplier_id')
->end();
generates:
CREATE TABLE categories_suppliers ( category_id int(11), supplier_id int(11) )
See also Horde_Db_Adapter_Base_TableDefinition::column() for details on how to create columns.
string | $name | A table name. |
array | $options | A list of table options, see the method description. |
The definition of the created table.
endTable(string|\Horde_Db_Adapter_Base_TableDefinition $name, array $options = array())
Finishes and executes table creation.
string|\Horde_Db_Adapter_Base_TableDefinition | $name | A table name or object. |
array | $options | A list of options. See createTable(). |
addColumn(string $tableName, string $columnName, string $type, array $options = array())
Adds a new column to a table.
string | $tableName | A table name. |
string | $columnName | A column name. |
string | $type | A data type. |
array | $options | Column options. See Horde_Db_Adapter_Base_TableDefinition#column() for details. |
changeColumn(string $tableName, string $columnName, string $type, array $options = array())
Changes an existing column's definition.
string | $tableName | A table name. |
string | $columnName | A column name. |
string | $type | A data type. |
array | $options | Column options. See Horde_Db_Adapter_Base_TableDefinition#column() for details. |
changeColumnDefault(string $tableName, string $columnName, mixed $default)
Sets a new default value for a column.
If you want to set the default value to NULL, you are out of luck. You need to execute the apppropriate SQL statement yourself.
string | $tableName | A table name. |
string | $columnName | A column name. |
mixed | $default | The new default value. |
addIndex(string $tableName, string|array $columnName, array $options = array()) : string
Adds a new index to a table.
The index will be named after the table and the first column names, unless you pass 'name' as an option.
When creating an index on multiple columns, the first column is used as a name for the index. For example, when you specify an index on two columns 'first' and 'last', the DBMS creates an index for both columns as well as an index for the first colum 'first'. Using just the first name for this index makes sense, because you will never have to create a singular index with this name.
Examples:
Creating a simple index
$schema->addIndex('suppliers', 'name');
generates
CREATE INDEX suppliers_name_index ON suppliers(name)
Creating a unique index
$schema->addIndex('accounts',
array('branch_id', 'party_id'),
array('unique' => true));
generates
CREATE UNIQUE INDEX accounts_branch_id_index ON accounts(branch_id, party_id)
Creating a named index
$schema->addIndex('accounts',
array('branch_id', 'party_id'),
array('unique' => true, 'name' => 'by_branch_party'));
generates
CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
string | $tableName | A table name. |
string|array | $columnName | One or more column names. |
array | $options | Index options:
|
The index name. @since Horde_Db 2.1.0
removeIndex(string $tableName, string|array $options = array())
Removes an index from a table.
Examples:
Remove the suppliers_name_index in the suppliers table:
$schema->removeIndex('suppliers', 'name');
Remove the index named accounts_branch_id in the accounts table:
$schema->removeIndex('accounts', array('column' => 'branch_id'));
Remove the index named by_branch_party in the accounts table:
$schema->removeIndex('accounts', array('name' => 'by_branch_party'));
You can remove an index on multiple columns by specifying the first
column:
$schema->addIndex('accounts', array('username', 'password'))
$schema->removeIndex('accounts', 'username');
string | $tableName | A table name. |
string|array | $options | Either a column name or index options:
|
indexName(string $tableName, string|array $options = array())
Builds the name for an index.
Cuts the index name to the maximum length of 64 characters limited by MySQL.
string | $tableName | A table name. |
string|array | $options | Either a column name or index options:
|
typeToSql(string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null) : string
Generates the SQL definition for a column type.
string | $type | A column type. |
integer | $limit | Maximum column length (non decimal type only) |
integer | $precision | The number precision (decimal type only). |
integer | $scale | The number scaling (decimal columns only). |
boolean | $unsigned | Whether the column is an unsigned number (non decimal columns only). |
The SQL definition. If $type is not one of the internally supported types, $type is returned unchanged.
addColumnOptions(string $sql, array $options) : string
Adds default/null options to column SQL definitions.
string | $sql | Existing SQL definition for a column. |
array | $options | Column options:
|
The manipulated SQL definition.
modifyDate(string $reference, string $operator, integer $amount, string $interval) : string
Generates a modified date for SELECT queries.
string | $reference | The reference date - this is a column referenced in the SELECT. |
string | $operator | Add or subtract time? (+/-) |
integer | $amount | The shift amount (number of days if $interval is DAY, etc). |
string | $interval | The interval (SECOND, MINUTE, HOUR, DAY, MONTH, YEAR). |
The generated INTERVAL clause.
None found |
buildClause(string $lhs, string $op, string $rhs, boolean $bind = false, array $params = array()) : string|array
Returns an expression using the specified operator.
string | $lhs | The column or expression to test. |
string | $op | The operator. |
string | $rhs | The comparison value. |
boolean | $bind | If true, the method returns the query and a list of values suitable for binding as an array. |
array | $params | Any additional parameters for the operator. |
The SQL test fragment, or an array containing the query and a list of values if $bind is true.
None found |
getCharset() : string
Returns the character set of query results.
The result's charset.
None found |
setCharset(string $charset)
Sets the client and result charset.
string | $charset | The character set to use for client queries and results. |
None found |
_mysqlCharsetName(string $charset) : string
Returns the MySQL name of a character set.
string | $charset | A charset name. |
MySQL-normalized charset.
None found |
getCollation() : string
Returns the database collation strategy.
Database collation.
None found |
showVariable(string $name) : string
Returns a database variable.
Convenience wrapper around "SHOW VARIABLES LIKE 'name'".
string | $name | A variable name. |
The variable value.
None found |
limitedUpdateConditions( $whereSql, $quotedTableName, $quotedPrimaryKey)
$whereSql | ||
$quotedTableName | ||
$quotedPrimaryKey |
None found |
_escapePrepare(string $query) : string
Escapes all characters in a string that are placeholders for prepare/execute methods.
string | $query | A string to escape. |
The correctly escaped string.
None found |
_clearTableCache(string $tableName)
Clears the cache for tables when altering them.
string | $tableName | A table name. |
None found |