Class yii\db\mysql\Schema

继承yii\db\mysql\Schema » yii\db\Schema » yii\base\BaseObject
实现yii\base\Configurable, yii\db\ConstraintFinderInterface
Uses Traitsyii\db\ConstraintFinderTrait
可用自版本2.0
源代码 https://github.com/yiisoft/yii2/blob/master/framework/db/mysql/Schema.php

Schema is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).

公共属性

隐藏继承的属性

属性类型描述定义在
$columnSchemaClass string|array Column schema class or class config yii\db\mysql\Schema
$db yii\db\Connection The database connection yii\db\Schema
$defaultSchema string The default schema name used for the current session. yii\db\Schema
$exceptionMap array Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used. yii\db\Schema
$lastInsertID string The row ID of the last row inserted, or the last value retrieved from the sequence object. This property is read-only. yii\db\Schema
$queryBuilder yii\db\QueryBuilder The query builder for this connection. This property is read-only. yii\db\Schema
$schemaChecks \yii\db\CheckConstraint[][] 数据库中所有表的检查约束. 每个数组元素都是 yii\db\CheckConstraint 或其子类的数组. 该属性是只读的. yii\db\ConstraintFinderTrait
$schemaDefaultValues yii\db\DefaultValueConstraint[] 数据库中所有表的默认值约束. 每个数组元素都是 yii\db\DefaultValueConstraint 或其子类的数组. 该属性是只读的. yii\db\ConstraintFinderTrait
$schemaForeignKeys \yii\db\ForeignKeyConstraint[][] 数据库中所有表的外键. 每个数组元素都是 yii\db\ForeignKeyConstraint 或其子类的数组. 该属性是只读的. yii\db\ConstraintFinderTrait
$schemaIndexes \yii\db\IndexConstraint[][] 数据库中所有表的索引. 每个数组元素都是 yii\db\IndexConstraint 或其子类的数组. 该属性是只读的. yii\db\ConstraintFinderTrait
$schemaNames string[] All schema names in the database, except system schemas. This property is read-only. yii\db\Schema
$schemaPrimaryKeys yii\db\Constraint[] 数据库中所有表的主键. 每个数组元素都是 yii\db\Constraint 或其子类的实例. 该属性是只读的. yii\db\ConstraintFinderTrait
$schemaUniques \yii\db\IndexConstraint[][] 数据库中所有表的唯一性约束. 每个数组元素都是 yii\db\IndexConstraint 或其子类的数组. 该属性是只读的. yii\db\ConstraintFinderTrait
$serverVersion string Server version as a string. This property is read-only. yii\db\Schema
$tableNames string[] All table names in the database. This property is read-only. yii\db\Schema
$tableSchemas yii\db\TableSchema[] The metadata for all tables in the database. Each array element is an instance of yii\db\TableSchema or its child class. This property is read-only. yii\db\Schema
$transactionIsolationLevel string The transaction isolation level to use for this transaction. This can be one of yii\db\Transaction::READ_UNCOMMITTED, yii\db\Transaction::READ_COMMITTED, yii\db\Transaction::REPEATABLE_READ and yii\db\Transaction::SERIALIZABLE but also a string containing DBMS specific syntax to be used after SET TRANSACTION ISOLATION LEVEL. This property is write-only. yii\db\Schema
$typeMap array Mapping from physical column types (keys) to abstract column types (values) yii\db\mysql\Schema

受保护的属性

隐藏继承的属性

属性类型描述定义在
$columnQuoteCharacter string|string[] Character used to quote column names. yii\db\mysql\Schema
$tableQuoteCharacter string|string[] Character used to quote schema, table, etc. yii\db\mysql\Schema

公共方法

隐藏继承的方法

方法描述定义在
__call() 调用不是类方法的已命名方法. yii\base\BaseObject
__construct() 构造函数. yii\base\BaseObject
__get() 返回对象属性的值. yii\base\BaseObject
__isset() 检查属性是否已设置, 即已定义且不为null. yii\base\BaseObject
__set() 设置对象属性的值. yii\base\BaseObject
__unset() 将对象属性设置为null. yii\base\BaseObject
canGetProperty() 返回一个值, 指示属性是否可读. yii\base\BaseObject
canSetProperty() 返回一个值, 指示属性是否可写. yii\base\BaseObject
className() 返回此类的完全限定名称. yii\base\BaseObject
convertException() Converts a DB exception to a more concrete one if possible. yii\db\Schema
createColumnSchemaBuilder() Create a column schema builder instance giving the type and value precision. yii\db\mysql\Schema
createQueryBuilder() Creates a query builder for the MySQL database. yii\db\mysql\Schema
createSavepoint() Creates a new savepoint. yii\db\Schema
findUniqueIndexes() Returns all unique indexes for the given table. yii\db\mysql\Schema
getLastInsertID() Returns the ID of the last inserted row or sequence value. yii\db\Schema
getPdoType() Determines the PDO type for the given PHP data value. yii\db\Schema
getQueryBuilder() yii\db\Schema
getRawTableName() Returns the actual name of a given table name. yii\db\Schema
getSchemaChecks() 返回数据库中所有表的检查约束. yii\db\ConstraintFinderTrait
getSchemaDefaultValues() 返回数据库中所有表的默认值约束. yii\db\ConstraintFinderTrait
getSchemaForeignKeys() 返回数据库中所有表的外键. yii\db\ConstraintFinderTrait
getSchemaIndexes() 返回数据库中所有表的索引. yii\db\ConstraintFinderTrait
getSchemaNames() Returns all schema names in the database, except system schemas. yii\db\Schema
getSchemaPrimaryKeys() 返回数据库中所有表的主键. yii\db\ConstraintFinderTrait
getSchemaUniques() 返回数据库中所有表的唯一性约束. yii\db\ConstraintFinderTrait
getServerVersion() Returns a server version as a string comparable by \version_compare(). yii\db\Schema
getTableChecks() 返回指定表的检查约束信息. yii\db\ConstraintFinderTrait
getTableDefaultValues() 返回指定表的默认值约束信息. yii\db\ConstraintFinderTrait
getTableForeignKeys() 获取指定表的外键信息. yii\db\ConstraintFinderTrait
getTableIndexes() 获取指定表的索引信息. yii\db\ConstraintFinderTrait
getTableNames() Returns all table names in the database. yii\db\Schema
getTablePrimaryKey() 获取指定表的主键. yii\db\ConstraintFinderTrait
getTableSchema() Obtains the metadata for the named table. yii\db\Schema
getTableSchemas() Returns the metadata for all tables in the database. yii\db\Schema
getTableUniques() 获取指定表的唯一性约束信息. yii\db\ConstraintFinderTrait
hasMethod() 返回一个值, 指示方法是否已定义. yii\base\BaseObject
hasProperty() 返回一个值, 指示属性是否已定义. yii\base\BaseObject
init() 初始化对象. yii\base\BaseObject
insert() Executes the INSERT command, returning primary key values. yii\db\Schema
isReadQuery() Returns a value indicating whether a SQL statement is for read purpose. yii\db\Schema
quoteColumnName() Quotes a column name for use in a query. yii\db\Schema
quoteSimpleColumnName() Quotes a simple column name for use in a query. yii\db\Schema
quoteSimpleTableName() Quotes a simple table name for use in a query. yii\db\Schema
quoteTableName() Quotes a table name for use in a query. yii\db\Schema
quoteValue() Quotes a string value for use in a query. yii\db\Schema
refresh() Refreshes the schema. yii\db\Schema
refreshTableSchema() Refreshes the particular table schema. yii\db\Schema
releaseSavepoint() Releases an existing savepoint. yii\db\Schema
rollBackSavepoint() Rolls back to a previously created savepoint. yii\db\Schema
setTransactionIsolationLevel() Sets the isolation level of the current transaction. yii\db\Schema
supportsSavepoint() yii\db\Schema
unquoteSimpleColumnName() Unquotes a simple column name. yii\db\Schema
unquoteSimpleTableName() Unquotes a simple table name. yii\db\Schema

受保护的方法

隐藏继承的方法

方法描述定义在
createColumnSchema() Creates a column schema for the database. yii\db\Schema
findColumns() Collects the metadata of table columns. yii\db\mysql\Schema
findConstraints() Collects the foreign key column details for the given table. yii\db\mysql\Schema
findSchemaNames() Returns all schema names in the database, including the default one but not system schemas. yii\db\Schema
findTableNames() Returns all table names in the database. yii\db\mysql\Schema
getCacheKey() Returns the cache key for the specified table name. yii\db\Schema
getCacheTag() Returns the cache tag name. yii\db\Schema
getColumnPhpType() Extracts the PHP type from abstract DB type. yii\db\Schema
getCreateTableSql() Gets the CREATE TABLE sql string. yii\db\mysql\Schema
getSchemaMetadata() 返回给定模式中所有表的给定类型的元数据. yii\db\ConstraintFinderTrait
getTableMetadata() 返回给定表的给定类型的元数据. yii\db\ConstraintFinderTrait
getTableNameParts() Splits full table name into parts yii\db\Schema
isOldMysql() yii\db\mysql\Schema
loadColumnSchema() Loads the column information into a yii\db\mysql\ColumnSchema object. yii\db\mysql\Schema
loadTableChecks() yii\db\mysql\Schema
loadTableDefaultValues() yii\db\mysql\Schema
loadTableForeignKeys() yii\db\mysql\Schema
loadTableIndexes() yii\db\mysql\Schema
loadTablePrimaryKey() yii\db\mysql\Schema
loadTableSchema() Loads the metadata for the specified table. yii\db\mysql\Schema
loadTableUniques() yii\db\mysql\Schema
normalizePdoRowKeyCase() Changes row's array key case to lower if PDO's one is set to uppercase. yii\db\Schema
resolveTableName() Resolves the table name and schema name (if any). yii\db\mysql\Schema
resolveTableNames() Resolves the table name and schema name (if any). yii\db\mysql\Schema
setTableMetadata() Sets the metadata of the given type for the given table. yii\db\Schema

常量

隐藏继承的常量

常量描述定义在
SCHEMA_CACHE_VERSION 1 Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. yii\db\Schema
TYPE_BIGINT 'bigint' yii\db\Schema
TYPE_BIGPK 'bigpk' yii\db\Schema
TYPE_BINARY 'binary' yii\db\Schema
TYPE_BOOLEAN 'boolean' yii\db\Schema
TYPE_CHAR 'char' yii\db\Schema
TYPE_DATE 'date' yii\db\Schema
TYPE_DATETIME 'datetime' yii\db\Schema
TYPE_DECIMAL 'decimal' yii\db\Schema
TYPE_DOUBLE 'double' yii\db\Schema
TYPE_FLOAT 'float' yii\db\Schema
TYPE_INTEGER 'integer' yii\db\Schema
TYPE_JSON 'json' yii\db\Schema
TYPE_MONEY 'money' yii\db\Schema
TYPE_PK 'pk' yii\db\Schema
TYPE_SMALLINT 'smallint' yii\db\Schema
TYPE_STRING 'string' yii\db\Schema
TYPE_TEXT 'text' yii\db\Schema
TYPE_TIME 'time' yii\db\Schema
TYPE_TIMESTAMP 'timestamp' yii\db\Schema
TYPE_TINYINT 'tinyint' yii\db\Schema
TYPE_UBIGPK 'ubigpk' yii\db\Schema
TYPE_UPK 'upk' yii\db\Schema

属性详情

$columnQuoteCharacter protected 属性 (可用自版本: 2.0.14)

Character used to quote column names. An array of 2 characters can be used in case starting and ending characters are different.

$columnSchemaClass public 属性 (可用自版本: 2.0.11)

Column schema class or class config

public string|array $columnSchemaClass 'yii\db\mysql\ColumnSchema'
$tableQuoteCharacter protected 属性 (可用自版本: 2.0.14)

Character used to quote schema, table, etc. names. An array of 2 characters can be used in case starting and ending characters are different.

$typeMap public 属性

Mapping from physical column types (keys) to abstract column types (values)

public array $typeMap = ['tinyint' => self::TYPE_TINYINT'bit' => self::TYPE_INTEGER'smallint' => self::TYPE_SMALLINT'mediumint' => self::TYPE_INTEGER'int' => self::TYPE_INTEGER'integer' => self::TYPE_INTEGER'bigint' => self::TYPE_BIGINT'float' => self::TYPE_FLOAT'double' => self::TYPE_DOUBLE'real' => self::TYPE_FLOAT'decimal' => self::TYPE_DECIMAL'numeric' => self::TYPE_DECIMAL'tinytext' => self::TYPE_TEXT'mediumtext' => self::TYPE_TEXT'longtext' => self::TYPE_TEXT'longblob' => self::TYPE_BINARY'blob' => self::TYPE_BINARY'text' => self::TYPE_TEXT'varchar' => self::TYPE_STRING'string' => self::TYPE_STRING'char' => self::TYPE_CHAR'datetime' => self::TYPE_DATETIME'year' => self::TYPE_DATE'date' => self::TYPE_DATE'time' => self::TYPE_TIME'timestamp' => self::TYPE_TIMESTAMP'enum' => self::TYPE_STRING'varbinary' => self::TYPE_BINARY'json' => self::TYPE_JSON]

方法详情

createColumnSchemaBuilder() public 方法 (可用自版本: 2.0.6)

Create a column schema builder instance giving the type and value precision.

This method may be overridden by child classes to create a DBMS-specific column schema builder.

public yii\db\ColumnSchemaBuilder createColumnSchemaBuilder ( $type, $length null )
$type string

Type of the column. See yii\db\mysql\ColumnSchemaBuilder::$type.

$length integer|string|array

Length or precision of the column. See yii\db\mysql\ColumnSchemaBuilder::$length.

return yii\db\ColumnSchemaBuilder

Column schema builder instance

createQueryBuilder() public 方法

Creates a query builder for the MySQL database.

public yii\db\mysql\QueryBuilder createQueryBuilder ( )
return yii\db\mysql\QueryBuilder

Query builder instance

findColumns() protected 方法

Collects the metadata of table columns.

protected boolean findColumns ( $table )
$table yii\db\TableSchema

The table metadata

return boolean

Whether the table exists in the database

throws Exception

if DB query fails

findConstraints() protected 方法

Collects the foreign key column details for the given table.

protected void findConstraints ( $table )
$table yii\db\TableSchema

The table metadata

throws Exception
findTableNames() protected 方法

Returns all table names in the database.

This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.

protected array findTableNames ( $schema '' )
$schema string

The schema of the tables. Defaults to empty string, meaning the current or default schema.

return array

All table names in the database. The names have NO schema name prefix.

throws yii\base\NotSupportedException

if this method is not supported by the DBMS.

findUniqueIndexes() public 方法

Returns all unique indexes for the given table.

Each array element is of the following structure:

[
    'IndexName1' => ['col1' [, ...]],
    'IndexName2' => ['col2' [, ...]],
]
public array findUniqueIndexes ( $table )
$table yii\db\TableSchema

The table metadata

return array

All unique indexes for the given table.

getCreateTableSql() protected 方法

Gets the CREATE TABLE sql string.

protected string getCreateTableSql ( $table )
$table yii\db\TableSchema

The table metadata

return string

$sql the result of 'SHOW CREATE TABLE'

isOldMysql() protected 方法 (可用自版本: 2.0.13)

protected boolean isOldMysql ( )
return boolean

Whether the version of the MySQL being used is older than 5.1.

throws yii\base\InvalidConfigException
throws yii\db\Exception
loadColumnSchema() protected 方法

Loads the column information into a yii\db\mysql\ColumnSchema object.

protected yii\db\mysql\ColumnSchema loadColumnSchema ( $info )
$info array

Column information

return yii\db\mysql\ColumnSchema

The column schema object

loadTableChecks() protected 方法

protected void loadTableChecks ( $tableName )
$tableName
throws yii\base\NotSupportedException

if this method is called.

loadTableDefaultValues() protected 方法

protected void loadTableDefaultValues ( $tableName )
$tableName
throws yii\base\NotSupportedException

if this method is called.

loadTableForeignKeys() protected 方法

protected void loadTableForeignKeys ( $tableName )
$tableName
loadTableIndexes() protected 方法

protected void loadTableIndexes ( $tableName )
$tableName
loadTablePrimaryKey() protected 方法

protected void loadTablePrimaryKey ( $tableName )
$tableName
loadTableSchema() protected 方法

Loads the metadata for the specified table.

protected yii\db\TableSchema|null loadTableSchema ( $name )
$name string

Table name

return yii\db\TableSchema|null

DBMS-dependent table metadata, null if the table does not exist.

loadTableUniques() protected 方法

protected void loadTableUniques ( $tableName )
$tableName
resolveTableName() protected 方法 (可用自版本: 2.0.13)

Resolves the table name and schema name (if any).

protected yii\db\TableSchema resolveTableName ( $name )
$name string

The table name

return yii\db\TableSchema

yii\db\TableSchema with resolved table, schema, etc. names.

throws yii\base\NotSupportedException

if this method is not supported by the DBMS.

resolveTableNames() protected 方法

Resolves the table name and schema name (if any).

protected void resolveTableNames ( $table, $name )
$table yii\db\TableSchema

The table metadata object

$name string

The table name