Свойство | Type | Description | |
---|---|---|---|
$_adapter | Horde_Db_Adapter_Base | A Horde_Db_Adapter instance. | |
$_adapterMethods | array | Method names are in the keys. |
Méthode | Description | |
---|---|---|
__call ( string $method, array $args ) : mixed | Delegates calls to the adapter object. | |
__construct ( Horde_Db_Adapter $adapter ) | Constructor. | |
__get ( string $key ) : object | Delegates access to $_cache and $_logger to the adapter object. | |
addColumn ( string $tableName, string $columnName, string $type, array $options = [] ) | Adds a new column to a table. | |
addColumnOptions ( string $sql, array $options ) : string | Adds default/null options to column SQL definitions. | |
addIndex ( string $tableName, string | array $columnName, array $options = [] ) : string | Adds a new index to a table. | |
addOrderByForAssocLimiting ( string $sql, array $options ) : string | Adds an ORDER BY clause to an existing query. | |
addPrimaryKey ( string $tableName, $columns ) | Adds a primary key to a table. | |
buildClause ( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = [] ) : string | array | Returns an expression using the specified operator. | |
changeColumn ( string $tableName, string $columnName, string $type, array $options = [] ) | Changes an existing column's definition. | |
changeColumnDefault ( string $tableName, string $columnName, mixed $default ) | Sets a new default value for a column. | |
column ( string $tableName, string $columnName ) : Horde_Db_Adapter_Base_Column | Returns a table column. | |
columns ( string $tableName, string $name = null ) : array | Returns a list of table columns. | |
createDatabase ( string $name, array $options = [] ) | Creates a database. | |
createTable ( string $name, array $options = [] ) : Horde_Db_Adapter_Base_TableDefinition | Creates a new table. | |
currentDatabase ( ) : string | Returns the name of the currently selected database. | |
distinct ( string $columns, string $orderBy = null ) : string | Generates a DISTINCT clause for SELECT queries. | |
dropDatabase ( string $name ) | Drops a database. | |
dropTable ( string $name ) | Drops a table from the database. | |
endTable ( string | Horde_Db_Adapter_Base_TableDefinition $name, array $options = [] ) | Finishes and executes table creation. | |
indexName ( string $tableName, string | array $options = [] ) | Builds the name for an index. | |
indexes ( string $tableName, string $name = null ) : array | Returns a list of tables indexes. | |
interval ( string $interval, string $precision ) : string | Generates an INTERVAL clause for SELECT queries. | |
makeColumn ( string $name, string $default, string $sqlType = null, boolean $null = true ) : Horde_Db_Adapter_Base_Column | Factory for Column objects. | |
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. | |
makeIndex ( string $table, string $name, boolean $primary, boolean $unique, array $columns ) : Horde_Db_Adapter_Base_Index | Factory for Index objects. | |
makeTable ( $name, $primaryKey, $columns, $indexes ) : Horde_Db_Adapter_Base_Table | Factory for Table objects. | |
makeTableDefinition ( $name, $base, $options = [] ) : Horde_Db_Adapter_Base_TableDefinition | Factory for TableDefinition objects. | |
modifyDate ( string $reference, string $operator, integer $amount, string $interval ) : string | Generates a modified date for SELECT queries. | |
nativeDatabaseTypes ( ) : array | Returns a hash of mappings from the abstract data types to the native database types. | |
primaryKey ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Index | Returns a table's primary key. | |
quote ( mixed $value, object $column = null ) : string | Quotes the column value to help prevent SQL injection attacks. | |
quoteBinary ( $value ) : string | Returns a quoted binary value. | |
quoteColumnName ( string $name ) : string | Returns a quoted form of the column name. | |
quoteDate ( $value ) : string | Returns a quoted date value. | |
quoteFalse ( ) : string | Returns a quoted boolean false. | |
quoteString ( string $string ) : string | Quotes a string, escaping any ' (single quote) and \ (backslash) characters. | |
quoteTableName ( string $name ) : string | Returns a quoted form of the table name. | |
quoteTrue ( ) : string | Returns a quoted boolean true. | |
recreateDatabase ( string $name ) | Recreates, i.e. drops then creates a database. | |
removeColumn ( string $tableName, string $columnName ) | Removes a column from a table. | |
removeIndex ( string $tableName, string | array $options = [] ) | Removes an index from a table. | |
removePrimaryKey ( string $tableName ) | Removes a primary key from a table. | |
renameColumn ( string $tableName, string $columnName, string $newColumnName ) | Renames a column. | |
renameTable ( string $name, string $newName ) | Renames a table. | |
setAdapter ( Horde_Db_Adapter $adapter ) | Setter for a Horde_Db_Adapter instance. | |
table ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Table | Returns a Horde_Db_Adapter_Base_Table object for a table. | |
tableAliasFor ( string $tableName ) : string | Converts a table name into a suitable table alias. | |
tableAliasLength ( ) : integer | Returns the maximum length a table alias can have. | |
tables ( ) : array | Returns a list of all tables of the current database. | |
typeToSql ( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null ) : string | Generates the SQL definition for a column type. |
Méthode | Description | |
---|---|---|
_clearTableCache ( string $tableName ) | Clears the cache for tables when altering them. | |
_escapePrepare ( string $query ) : string | Escapes all characters in a string that are placeholders for prepare/execute methods. |
public __construct ( Horde_Db_Adapter $adapter ) | ||
$adapter | Horde_Db_Adapter | A Horde_Db_Adapter instance. |
protected _clearTableCache ( string $tableName ) | ||
$tableName | string | A table name. |
protected _escapePrepare ( string $query ) : string | ||
$query | string | A string to escape. |
Résultat | string | The correctly escaped string. |
public addColumnOptions ( string $sql, array $options ) : string | ||
$sql | string | Existing SQL definition for a column. |
$options | array | Column options: - column: (Horde_Db_Adapter_Base_ColumnDefinition The column definition class. - null: (boolean) Whether to allow NULL values. - default: (mixed) Default column value. - autoincrement: (boolean) Whether the column is an autoincrement column. Driver depedendent. |
Résultat | string | The manipulated SQL definition. |
$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)
public addIndex ( string $tableName, string | array $columnName, array $options = [] ) : string | ||
$tableName | string | A table name. |
$columnName | string | array | One or more column names. |
$options | array | Index options: - name: (string) the index name. - unique: (boolean) create a unique index? |
Résultat | string | The index name. @since Horde_Db 2.1.0 |
public addPrimaryKey ( string $tableName, $columns ) | ||
$tableName | string | A table name. |
public buildClause ( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = [] ) : string | array | ||
$lhs | string | The column or expression to test. |
$op | string | The operator. |
$rhs | string | The comparison value. |
$bind | boolean | If true, the method returns the query and a list of values suitable for binding as an array. |
$params | array | Any additional parameters for the operator. |
Résultat | string | array | The SQL test fragment, or an array containing the query and a list of values if $bind is true. |
abstract public createDatabase ( string $name, array $options = [] ) | ||
$name | string | A database name. |
$options | array | Database options. |
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.
public createTable ( string $name, array $options = [] ) : Horde_Db_Adapter_Base_TableDefinition | ||
$name | string | A table name. |
$options | array | A list of table options, see the method description. |
Résultat | Horde_Db_Adapter_Base_TableDefinition | The definition of the created table. |
abstract public currentDatabase ( ) : string | ||
Résultat | string | The database name. |
$connection->distinct('posts.id', 'posts.created_at DESC')
abstract public dropDatabase ( string $name ) | ||
$name | string | A database name. |
public makeColumn ( string $name, string $default, string $sqlType = null, boolean $null = true ) : Horde_Db_Adapter_Base_Column | ||
$name | string | The column's name, such as "supplier_id" in "supplier_id int(11)". |
$default | string | The type-casted default value, such as "new" in "sales_stage varchar(20) default 'new'". |
$sqlType | string | 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". |
$null | boolean | Whether this column allows NULL values. |
Résultat | Horde_Db_Adapter_Base_Column | A column object. |
public makeColumnDefinition ( $base, $name, $type, $limit = null, $precision = null, $scale = null, $unsigned = null, $default = null, $null = null, $autoincrement = null ) : Horde_Db_Adapter_Base_ColumnDefinition | ||
Résultat | Horde_Db_Adapter_Base_ColumnDefinition | A column definition object. |
public makeIndex ( string $table, string $name, boolean $primary, boolean $unique, array $columns ) : Horde_Db_Adapter_Base_Index | ||
$table | string | The table the index is on. |
$name | string | The index's name. |
$primary | boolean | Is this a primary key? |
$unique | boolean | Is this a unique index? |
$columns | array | The columns this index covers. |
Résultat | Horde_Db_Adapter_Base_Index | An index object. |
public makeTable ( $name, $primaryKey, $columns, $indexes ) : Horde_Db_Adapter_Base_Table | ||
Résultat | Horde_Db_Adapter_Base_Table | A table object. |
public makeTableDefinition ( $name, $base, $options = [] ) : Horde_Db_Adapter_Base_TableDefinition | ||
Résultat | Horde_Db_Adapter_Base_TableDefinition | A table definition object. |
public modifyDate ( string $reference, string $operator, integer $amount, string $interval ) : string | ||
$reference | string | The reference date - this is a column referenced in the SELECT. |
$operator | string | Add or subtract time? (+/-) |
$amount | integer | The shift amount (number of days if $interval is DAY, etc). |
$interval | string | The interval (SECOND, MINUTE, HOUR, DAY, MONTH, YEAR). |
Résultat | string | The generated INTERVAL clause. |
abstract public nativeDatabaseTypes ( ) : array | ||
Résultat | array | A database type map. |
abstract public primaryKey ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Index | ||
$tableName | string | A table name. |
$name | string | (can be removed?) |
Résultat | Horde_Db_Adapter_Base_Index | The primary key index object. |
public quoteBinary ( $value ) : string | ||
Résultat | string | The quoted binary value. |
public quoteColumnName ( string $name ) : string | ||
$name | string | A column name. |
Résultat | string | The quoted column name. |
public quoteFalse ( ) : string | ||
Résultat | string | The quoted boolean false. |
public quoteString ( string $string ) : string | ||
$string | string | A string to escape. |
Résultat | string | The escaped and quoted string. |
public quoteTableName ( string $name ) : string | ||
$name | string | A table name. |
Résultat | string | The quoted table name. |
public recreateDatabase ( string $name ) | ||
$name | string | A database name. |
public removeColumn ( string $tableName, string $columnName ) | ||
$tableName | string | A table name. |
$columnName | string | A column name. |
$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');
abstract public removePrimaryKey ( string $tableName ) | ||
$tableName | string | A table name. |
abstract public renameTable ( string $name, string $newName ) | ||
$name | string | A table name. |
$newName | string | The new table name. |
public setAdapter ( Horde_Db_Adapter $adapter ) | ||
$adapter | Horde_Db_Adapter | A Horde_Db_Adapter instance. |
public tableAliasFor ( string $tableName ) : string | ||
$tableName | string | A table name. |
Résultat | string | A possible alias name for the table. |
public tableAliasLength ( ) : integer | ||
Résultat | integer | The maximum table alias length. |
public typeToSql ( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null ) : string | ||
$type | string | A column type. |
$limit | integer | Maximum column length (non decimal type only) |
$precision | integer | The number precision (decimal type only). |
$scale | integer | The number scaling (decimal columns only). |
$unsigned | boolean | Whether the column is an unsigned number (non decimal columns only). |
Résultat | string | The SQL definition. If $type is not one of the internally supported types, $type is returned unchanged. |
protected Horde_Db_Adapter_Base $_adapter | ||
Résultat | Horde_Db_Adapter_Base |
protected array $_adapterMethods | ||
Résultat | array |