# Schema

> Schema is the base class for concrete DBMS-specific schema classes.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › Schema

| abstract class | `yii\db\Schema` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/db/Schema.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/Schema.php#L62) |

5 subclasses:

- [`yii\db\mssql\Schema`](/docs/api/yii/db/mssql/schema/index.md)
- [`yii\db\mysql\Schema`](/docs/api/yii/db/mysql/schema/index.md)
- [`yii\db\oci\Schema`](/docs/api/yii/db/oci/schema/index.md)
- [`yii\db\pgsql\Schema`](/docs/api/yii/db/pgsql/schema/index.md)
- [`yii\db\sqlite\Schema`](/docs/api/yii/db/sqlite/schema/index.md)

Schema is the base class for concrete DBMS-specific schema classes.

Schema represents the database schema information that is DBMS specific.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-columnSchemaClass"></span>`$columnSchemaClass` | `class-string<yii\db\T>\|array{class?: class-string<yii\db\T>, __class?: class-string<yii\db\T>}` | Column schema class or class config Default: `'yii\db\ColumnSchema'`. Available since 2.0.11. | `Schema` |
| <span id="property-db"></span>`$db` | [`Connection`](/docs/api/yii/db/connection/index.md) | The database connection Default: `null`. | `Schema` |
| <span id="property-defaultSchema"></span>`$defaultSchema` | `string` | The default schema name used for the current session. Default: `null`. | `Schema` |
| <span id="property-exceptionMap"></span>`$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. Default: `['SQLSTATE[23' => 'yii\db\IntegrityException']`. | `Schema` |
| <span id="property-lastInsertID"></span>`$lastInsertID` read-only | `string` | The row ID of the last row inserted, or the last value retrieved from the sequence object. | `Schema` |
| <span id="property-queryBuilder"></span>`$queryBuilder` read-only | `yii\db\TQueryBuilder` | The query builder for this connection. | `Schema` |
| <span id="property-schemaNames"></span>`$schemaNames` read-only | `string[]` | All schema names in the database, except system schemas. | `Schema` |
| <span id="property-serverVersion"></span>`$serverVersion` read-only | `string` | Server version as a string. | `Schema` |
| [`$systemSchemaNames`](#property-systemSchemaNames) | `list<string>` | List of schema names that should be excluded from [`getSchemaNames()`](/docs/api/yii/db/schema/index.md#method-getSchemaNames). Default: `[]`. | `Schema` |
| <span id="property-tableNames"></span>`$tableNames` read-only | `string[]` | All table names in the database. | `Schema` |
| [`$tableSchemas`](#property-tableSchemas) read-only | [`TableSchema`](/docs/api/yii/db/tableschema/index.md)`[]` | The metadata for all tables in the database. | `Schema` |
| [`$transactionIsolationLevel`](#property-transactionIsolationLevel) write-only | `string` | The transaction isolation level to use for this transaction. | `Schema` |
| [`$columnQuoteCharacter`](#property-columnQuoteCharacter) protected | `string\|string[]` | Character used to quote column names. Default: `'"'`. Available since 2.0.14. | `Schema` |
| [`$tableQuoteCharacter`](#property-tableQuoteCharacter) protected | `string\|string[]` | Character used to quote schema, table, etc. names. Default: `"'"`. Available since 2.0.14. | `Schema` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`convertException()`](#method-convertException) | Converts a DB exception to a more concrete one if possible. | `Schema` |
| [`createColumnSchemaBuilder()`](#method-createColumnSchemaBuilder) | Create a column schema builder instance giving the type and value precision. | `Schema` |
| [`createQueryBuilder()`](#method-createQueryBuilder) | Creates a query builder for the database. | `Schema` |
| [`createSavepoint()`](#method-createSavepoint) | Creates a new savepoint. | `Schema` |
| [`findUniqueIndexes()`](#method-findUniqueIndexes) | Returns all unique indexes for the given table. | `Schema` |
| [`getLastInsertID()`](#method-getLastInsertID) | Returns the ID of the last inserted row or sequence value. | `Schema` |
| [`getPdoType()`](#method-getPdoType) | Determines the PDO type for the given PHP data value. | `Schema` |
| [`getQueryBuilder()`](#method-getQueryBuilder) |  | `Schema` |
| [`getRawTableName()`](#method-getRawTableName) | Returns the actual name of a given table name. | `Schema` |
| [`getSchemaNames()`](#method-getSchemaNames) | Returns all schema names in the database, except system schemas. | `Schema` |
| [`getServerVersion()`](#method-getServerVersion) | Returns a server version as a string comparable by [`version_compare()`](https://www.php.net/manual/en/function.version-compare.php). | `Schema` |
| [`getTableNames()`](#method-getTableNames) | Returns all table names in the database. | `Schema` |
| [`getTableSchema()`](#method-getTableSchema) | Obtains the metadata for the named table. | `Schema` |
| [`getTableSchemas()`](#method-getTableSchemas) | Returns the metadata for all tables in the database. | `Schema` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`insert()`](#method-insert) | Executes the INSERT command, returning primary key values. | `Schema` |
| [`isReadQuery()`](#method-isReadQuery) | Returns a value indicating whether a SQL statement is for read purpose. | `Schema` |
| [`quoteColumnName()`](#method-quoteColumnName) | Quotes a column name for use in a query. | `Schema` |
| [`quoteSimpleColumnName()`](#method-quoteSimpleColumnName) | Quotes a simple column name for use in a query. | `Schema` |
| [`quoteSimpleTableName()`](#method-quoteSimpleTableName) | Quotes a simple table name for use in a query. | `Schema` |
| [`quoteTableName()`](#method-quoteTableName) | Quotes a table name for use in a query. | `Schema` |
| [`quoteValue()`](#method-quoteValue) | Quotes a string value for use in a query. | `Schema` |
| [`refresh()`](#method-refresh) | Refreshes the schema. | `Schema` |
| [`refreshTableSchema()`](#method-refreshTableSchema) | Refreshes the particular table schema. | `Schema` |
| [`releaseSavepoint()`](#method-releaseSavepoint) | Releases an existing savepoint. | `Schema` |
| [`resolveRawTableName()`](#method-resolveRawTableName) | Resolves the table name and schema name (if any) without loading database metadata. | `Schema` |
| [`rollBackSavepoint()`](#method-rollBackSavepoint) | Rolls back to a previously created savepoint. | `Schema` |
| [`setTransactionIsolationLevel()`](#method-setTransactionIsolationLevel) | Sets the isolation level of the current transaction. | `Schema` |
| [`supportsSavepoint()`](#method-supportsSavepoint) |  | `Schema` |
| [`unquoteSimpleColumnName()`](#method-unquoteSimpleColumnName) | Unquotes a simple column name. | `Schema` |
| [`unquoteSimpleTableName()`](#method-unquoteSimpleTableName) | Unquotes a simple table name. | `Schema` |
| [`createColumnSchema()`](#method-createColumnSchema) protected | Creates a column schema for the database. | `Schema` |
| [`findSchemaNames()`](#method-findSchemaNames) protected | Returns all schema names in the database, including the default one but not system schemas. | `Schema` |
| [`findTableNames()`](#method-findTableNames) protected | Returns all table names in the database. | `Schema` |
| [`getCacheKey()`](#method-getCacheKey) protected | Returns the cache key for the specified table name. | `Schema` |
| [`getCacheTag()`](#method-getCacheTag) protected | Returns the cache tag name. | `Schema` |
| [`getColumnPhpType()`](#method-getColumnPhpType) protected | Extracts the PHP type from abstract DB type. | `Schema` |
| [`getSchemaMetadata()`](#method-getSchemaMetadata) protected | Returns the metadata of the given type for all tables in the given schema. | `Schema` |
| [`getTableMetadata()`](#method-getTableMetadata) protected | Returns the metadata of the given type for the given table. | `Schema` |
| [`getTableNameParts()`](#method-getTableNameParts) protected | Splits full table name into parts. | `Schema` |
| [`loadTableSchema()`](#method-loadTableSchema) protected abstract | Loads the metadata for the specified table. | `Schema` |
| [`normalizePdoRowKeyCase()`](#method-normalizePdoRowKeyCase) protected | Changes row's array key case to lower if PDO's one is set to uppercase. | `Schema` |
| [`resolveTableName()`](#method-resolveTableName) protected | Resolves the table name and schema name (if any). | `Schema` |
| [`setTableMetadata()`](#method-setTableMetadata) protected | Sets the metadata of the given type for the given table. | `Schema` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-TYPE_PK"></span>`TYPE_PK` | `'pk'` |  | `Schema` |
| <span id="const-TYPE_UPK"></span>`TYPE_UPK` | `'upk'` |  | `Schema` |
| <span id="const-TYPE_BIGPK"></span>`TYPE_BIGPK` | `'bigpk'` |  | `Schema` |
| <span id="const-TYPE_UBIGPK"></span>`TYPE_UBIGPK` | `'ubigpk'` |  | `Schema` |
| <span id="const-TYPE_CHAR"></span>`TYPE_CHAR` | `'char'` |  | `Schema` |
| <span id="const-TYPE_STRING"></span>`TYPE_STRING` | `'string'` |  | `Schema` |
| <span id="const-TYPE_TEXT"></span>`TYPE_TEXT` | `'text'` |  | `Schema` |
| <span id="const-TYPE_TINYINT"></span>`TYPE_TINYINT` | `'tinyint'` |  | `Schema` |
| <span id="const-TYPE_SMALLINT"></span>`TYPE_SMALLINT` | `'smallint'` |  | `Schema` |
| <span id="const-TYPE_INTEGER"></span>`TYPE_INTEGER` | `'integer'` |  | `Schema` |
| <span id="const-TYPE_BIGINT"></span>`TYPE_BIGINT` | `'bigint'` |  | `Schema` |
| <span id="const-TYPE_FLOAT"></span>`TYPE_FLOAT` | `'float'` |  | `Schema` |
| <span id="const-TYPE_DOUBLE"></span>`TYPE_DOUBLE` | `'double'` |  | `Schema` |
| <span id="const-TYPE_DECIMAL"></span>`TYPE_DECIMAL` | `'decimal'` |  | `Schema` |
| <span id="const-TYPE_DATETIME"></span>`TYPE_DATETIME` | `'datetime'` |  | `Schema` |
| <span id="const-TYPE_TIMESTAMP"></span>`TYPE_TIMESTAMP` | `'timestamp'` |  | `Schema` |
| <span id="const-TYPE_TIME"></span>`TYPE_TIME` | `'time'` |  | `Schema` |
| <span id="const-TYPE_DATE"></span>`TYPE_DATE` | `'date'` |  | `Schema` |
| <span id="const-TYPE_BINARY"></span>`TYPE_BINARY` | `'binary'` |  | `Schema` |
| <span id="const-TYPE_BOOLEAN"></span>`TYPE_BOOLEAN` | `'boolean'` |  | `Schema` |
| <span id="const-TYPE_MONEY"></span>`TYPE_MONEY` | `'money'` |  | `Schema` |
| <span id="const-TYPE_JSON"></span>`TYPE_JSON` | `'json'` |  | `Schema` |
| <span id="const-SCHEMA_CACHE_VERSION"></span>`SCHEMA_CACHE_VERSION` | `1` | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. | `Schema` |

## Property details

### $systemSchemaNames <span id="property-systemSchemaNames"></span>

```php
public list<string> $systemSchemaNames = []
```

List of schema names that should be excluded from [`getSchemaNames()`](/docs/api/yii/db/schema/index.md#method-getSchemaNames).

DBMS-specific implementations may use this list in [`findSchemaNames()`](/docs/api/yii/db/schema/index.md#method-findSchemaNames).

### $tableSchemas <span id="property-tableSchemas"></span>

```php
public yii\db\TableSchema[] $tableSchemas
```

The metadata for all tables in the database.

Each array element
is an instance of [`TableSchema`](/docs/api/yii/db/tableschema/index.md) or its child class.

**Access**

Read-only (virtual property).

### $transactionIsolationLevel <span id="property-transactionIsolationLevel"></span>

```php
public string $transactionIsolationLevel
```

The transaction isolation level to use for this transaction.

This can be one of [`Transaction::READ_UNCOMMITTED`](/docs/api/yii/db/transaction/index.md#const-READ_UNCOMMITTED), [`Transaction::READ_COMMITTED`](/docs/api/yii/db/transaction/index.md#const-READ_COMMITTED),
[`Transaction::REPEATABLE_READ`](/docs/api/yii/db/transaction/index.md#const-REPEATABLE_READ) and [`Transaction::SERIALIZABLE`](/docs/api/yii/db/transaction/index.md#const-SERIALIZABLE) but also a string containing DBMS specific
syntax to be used after `SET TRANSACTION ISOLATION LEVEL`.

**Access**

Write-only (virtual property).

### $columnQuoteCharacter <span id="property-columnQuoteCharacter"></span>

```php
protected string|string[] $columnQuoteCharacter = '"'
```

Character used to quote column names.

An array of 2 characters can be used in case starting and ending characters are different.

**Since**

2.0.14

### $tableQuoteCharacter <span id="property-tableQuoteCharacter"></span>

```php
protected string|string[] $tableQuoteCharacter = "'"
```

Character used to quote schema, table, etc. names.

An array of 2 characters can be used in case starting and ending characters are different.

**Since**

2.0.14

## Method details

### convertException() <span id="method-convertException"></span>

```php
public function convertException(Exception $e, string $rawSql): yii\db\Exception
```

Converts a DB exception to a more concrete one if possible.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$e` | [`Exception`](https://www.php.net/manual/en/class.exception.php) |  |
| `$rawSql` | `string` | SQL that produced exception |

**Returns**

[`Exception`](/docs/api/yii/db/exception/index.md)

### createColumnSchemaBuilder() <span id="method-createColumnSchemaBuilder"></span>

```php
public function createColumnSchemaBuilder(string $type, int|string|array|null $length = null): yii\db\ColumnSchemaBuilder
```

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.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | Type of the column. See [`ColumnSchemaBuilder::$type`](/docs/api/yii/db/columnschemabuilder/index.md#property-type). |
| `$length` | `int\|string\|array\|null` | Length or precision of the column. See [`ColumnSchemaBuilder::$length`](/docs/api/yii/db/columnschemabuilder/index.md#property-length). |

**Returns**

[`ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md): Column schema builder instance

**Since**

2.0.6

### createQueryBuilder() <span id="method-createQueryBuilder"></span>

```php
public function createQueryBuilder(): yii\db\TQueryBuilder
```

Creates a query builder for the database.

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

**Returns**

`yii\db\TQueryBuilder`: Query builder instance

### createSavepoint() <span id="method-createSavepoint"></span>

```php
public function createSavepoint(string $name): mixed
```

Creates a new savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The savepoint name |

**Returns**

`mixed`

### findUniqueIndexes() <span id="method-findUniqueIndexes"></span>

```php
public function findUniqueIndexes(yii\db\TableSchema $table): array
```

Returns all unique indexes for the given table.

Each array element is of the following structure:

```
[
 'IndexName1' => ['col1' [, ...]],
 'IndexName2' => ['col2' [, ...]],
]
```

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | [`TableSchema`](/docs/api/yii/db/tableschema/index.md) | The table metadata |

**Returns**

`array`: All unique indexes for the given table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is called

### getLastInsertID() <span id="method-getLastInsertID"></span>

```php
public function getLastInsertID(string $sequenceName = ''): string
```

Returns the ID of the last inserted row or sequence value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sequenceName` | `string` | Name of the sequence object (required by some DBMS) |

**Returns**

`string`: The row ID of the last row inserted, or the last value retrieved from the sequence object

**Throws**

- [`yii\base\InvalidCallException`](/docs/api/yii/base/invalidcallexception/index.md): if the DB connection is not active

**See also**

- <https://www.php.net/manual/en/function.PDO-lastInsertId.php>

### getPdoType() <span id="method-getPdoType"></span>

```php
public function getPdoType(mixed $data): int
```

Determines the PDO type for the given PHP data value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `mixed` | The data whose PDO type is to be determined |

**Returns**

`int`: The PDO type

**See also**

- <https://www.php.net/manual/en/pdo.constants.php>

### getQueryBuilder() <span id="method-getQueryBuilder"></span>

```php
public function getQueryBuilder(): yii\db\TQueryBuilder
```

**Returns**

`yii\db\TQueryBuilder`: The query builder for this connection.

### getRawTableName() <span id="method-getRawTableName"></span>

```php
public function getRawTableName(string $name): string
```

Returns the actual name of a given table name.

This method will strip off curly brackets from the given table name
and replace the percentage character '%' with [`Connection::$tablePrefix`](/docs/api/yii/db/connection/index.md#property-tablePrefix).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The table name to be converted |

**Returns**

`string`: The real name of the given table name

### getSchemaNames() <span id="method-getSchemaNames"></span>

```php
public function getSchemaNames(bool $refresh = false): string[]
```

Returns all schema names in the database, except system schemas.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$refresh` | `bool` | Whether to fetch the latest available schema names. If this is false, schema names fetched previously (if available) will be returned. |

**Returns**

`string[]`: All schema names in the database, except system schemas.

**Since**

2.0.4

### getServerVersion() <span id="method-getServerVersion"></span>

```php
public function getServerVersion(): string
```

Returns a server version as a string comparable by [`version_compare()`](https://www.php.net/manual/en/function.version-compare.php).

**Returns**

`string`: Server version as a string.

**Since**

2.0.14

### getTableNames() <span id="method-getTableNames"></span>

```php
public function getTableNames(string $schema = '', bool $refresh = false): string[]
```

Returns all table names in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. If not empty, the returned table names will be prefixed with the schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table names. If this is false, table names fetched previously (if available) will be returned. |

**Returns**

`string[]`: All table names in the database.

### getTableSchema() <span id="method-getTableSchema"></span>

```php
public function getTableSchema(string $name, bool $refresh = false): yii\db\TableSchema|null
```

Obtains the metadata for the named table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$refresh` | `bool` | Whether to reload the table schema even if it is found in the cache. |

**Returns**

[`TableSchema`](/docs/api/yii/db/tableschema/index.md)`|null`: Table metadata. `null` if the named table does not exist.

### getTableSchemas() <span id="method-getTableSchemas"></span>

```php
public function getTableSchemas(string $schema = '', bool $refresh = false): yii\db\TableSchema[]
```

Returns the metadata for all tables in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available table schemas. If this is `false`, cached data may be returned if available. |

**Returns**

[`TableSchema`](/docs/api/yii/db/tableschema/index.md)`[]`: The metadata for all tables in the database. Each array element is an instance of [`TableSchema`](/docs/api/yii/db/tableschema/index.md) or its child class.

### insert() <span id="method-insert"></span>

```php
public function insert(string $table, array $columns): array|false
```

Executes the INSERT command, returning primary key values.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table that new rows will be inserted into. |
| `$columns` | `array` | The column data (name => value) to be inserted into the table. |

**Returns**

`array|false`: Primary key values or false if the command fails

**Since**

2.0.4

### isReadQuery() <span id="method-isReadQuery"></span>

```php
public function isReadQuery(string $sql): bool
```

Returns a value indicating whether a SQL statement is for read purpose.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sql` | `string` | The SQL statement |

**Returns**

`bool`: Whether a SQL statement is for read purpose.

### quoteColumnName() <span id="method-quoteColumnName"></span>

```php
public function quoteColumnName(string $name): string
```

Quotes a column name for use in a query.

If the column name contains prefix, the prefix will also be properly quoted.
If the column name is already fully enclosed in the quote characters, or contains '(', '[[' or '{{', then this
method will do nothing.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Column name. |

**Returns**

`string`: The properly quoted column name.

**See also**

- [`quoteSimpleColumnName()`](/docs/api/yii/db/schema/index.md#method-quoteSimpleColumnName)

### quoteSimpleColumnName() <span id="method-quoteSimpleColumnName"></span>

```php
public function quoteSimpleColumnName(string $name): string
```

Quotes a simple column name for use in a query.

A simple column name should contain the column name only without any prefix.
The asterisk character '*' and a name already fully enclosed in the quote characters are returned as is;
otherwise the name is enclosed and any embedded ending quote character is escaped by doubling it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Column name. |

**Returns**

`string`: The properly quoted column name.

### quoteSimpleTableName() <span id="method-quoteSimpleTableName"></span>

```php
public function quoteSimpleTableName(string $name): string
```

Quotes a simple table name for use in a query.

A simple table name should contain the table name only without any schema prefix.
A name already fully enclosed in the quote characters is returned as is; otherwise the name is enclosed and any
embedded ending quote character is escaped by doubling it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. |

**Returns**

`string`: The properly quoted table name.

### quoteTableName() <span id="method-quoteTableName"></span>

```php
public function quoteTableName(string $name): string
```

Quotes a table name for use in a query.

If the table name contains schema prefix, the prefix will also be properly quoted.
If the table name is already fully enclosed in the quote characters, or contains '(' or '{{', then this method
will do nothing.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. |

**Returns**

`string`: The properly quoted table name.

**See also**

- [`quoteSimpleTableName()`](/docs/api/yii/db/schema/index.md#method-quoteSimpleTableName)

### quoteValue() <span id="method-quoteValue"></span>

```php
public function quoteValue(mixed $str): mixed
```

Quotes a string value for use in a query.

Note that if the parameter is not a string, it will be returned without change.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$str` | `mixed` | String to be quoted. If the parameter is not a string, it will be returned without change. |

**Returns**

`mixed`: The properly quoted string, or the original data if it is not a string.

**See also**

- <https://www.php.net/manual/en/function.PDO-quote.php>

### refresh() <span id="method-refresh"></span>

```php
public function refresh(): mixed
```

Refreshes the schema.

This method cleans up all cached table schemas so that they can be re-created later
to reflect the database schema change.

**Returns**

`mixed`

### refreshTableSchema() <span id="method-refreshTableSchema"></span>

```php
public function refreshTableSchema(string $name): mixed
```

Refreshes the particular table schema.

This method cleans up cached table schema so that it can be re-created later
to reflect the database schema change.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. |

**Returns**

`mixed`

**Since**

2.0.6

### releaseSavepoint() <span id="method-releaseSavepoint"></span>

```php
public function releaseSavepoint(string $name): mixed
```

Releases an existing savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The savepoint name |

**Returns**

`mixed`

### resolveRawTableName() <span id="method-resolveRawTableName"></span>

```php
public function resolveRawTableName(string $name): yii\db\TableSchema
```

Resolves the table name and schema name (if any) without loading database metadata.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The table name. |

**Returns**

[`TableSchema`](/docs/api/yii/db/tableschema/index.md): TableSchema with resolved table, schema, etc. names.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

**Since**

22.0

### rollBackSavepoint() <span id="method-rollBackSavepoint"></span>

```php
public function rollBackSavepoint(string $name): mixed
```

Rolls back to a previously created savepoint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The savepoint name |

**Returns**

`mixed`

### setTransactionIsolationLevel() <span id="method-setTransactionIsolationLevel"></span>

```php
public function setTransactionIsolationLevel(string $level): mixed
```

Sets the isolation level of the current transaction.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$level` | `string` | The transaction isolation level to use for this transaction. This can be one of [`Transaction::READ_UNCOMMITTED`](/docs/api/yii/db/transaction/index.md#const-READ_UNCOMMITTED), [`Transaction::READ_COMMITTED`](/docs/api/yii/db/transaction/index.md#const-READ_COMMITTED), [`Transaction::REPEATABLE_READ`](/docs/api/yii/db/transaction/index.md#const-REPEATABLE_READ) and [`Transaction::SERIALIZABLE`](/docs/api/yii/db/transaction/index.md#const-SERIALIZABLE) but also a string containing DBMS specific syntax to be used after `SET TRANSACTION ISOLATION LEVEL`. |

**Returns**

`mixed`

**See also**

- <https://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels>

### supportsSavepoint() <span id="method-supportsSavepoint"></span>

```php
public function supportsSavepoint(): bool
```

**Returns**

`bool`: Whether this DBMS supports [savepoint](https://en.wikipedia.org/wiki/Savepoint).

### unquoteSimpleColumnName() <span id="method-unquoteSimpleColumnName"></span>

```php
public function unquoteSimpleColumnName(string $name): string
```

Unquotes a simple column name.

A simple column name should contain the column name only without any prefix.
Only a name fully enclosed in the quote characters is unquoted: the enclosure is stripped and doubled ending
quote characters are collapsed to a single one.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Column name. |

**Returns**

`string`: Unquoted column name.

**Since**

2.0.14

### unquoteSimpleTableName() <span id="method-unquoteSimpleTableName"></span>

```php
public function unquoteSimpleTableName(string $name): string
```

Unquotes a simple table name.

A simple table name should contain the table name only without any schema prefix.
Only a name fully enclosed in the quote characters is unquoted: the enclosure is stripped and doubled ending
quote characters are collapsed to a single one.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. |

**Returns**

`string`: Unquoted table name.

**Since**

2.0.14

### createColumnSchema() <span id="method-createColumnSchema"></span>

```php
protected function createColumnSchema(): yii\db\T
```

Creates a column schema for the database.

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

**Returns**

`yii\db\T`: Column schema instance.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if a column schema class cannot be created.

### findSchemaNames() <span id="method-findSchemaNames"></span>

```php
protected function findSchemaNames(): array
```

Returns all schema names in the database, including the default one but not system schemas.

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

**Returns**

`array`: All schema names in the database, except system schemas.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

**Since**

2.0.4

### findTableNames() <span id="method-findTableNames"></span>

```php
protected function findTableNames(string $schema = ''): array
```

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.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the tables. Defaults to empty string, meaning the current or default schema. |

**Returns**

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

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

### getCacheKey() <span id="method-getCacheKey"></span>

```php
protected function getCacheKey(string $name): mixed
```

Returns the cache key for the specified table name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The table name. |

**Returns**

`mixed`: The cache key.

### getCacheTag() <span id="method-getCacheTag"></span>

```php
protected function getCacheTag(): string
```

Returns the cache tag name.

This allows [`refresh()`](/docs/api/yii/db/schema/index.md#method-refresh) to invalidate all cached table schemas.

**Returns**

`string`: The cache tag name

### getColumnPhpType() <span id="method-getColumnPhpType"></span>

```php
protected function getColumnPhpType(yii\db\ColumnSchema $column): string
```

Extracts the PHP type from abstract DB type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$column` | [`ColumnSchema`](/docs/api/yii/db/columnschema/index.md) | The column schema information |

**Returns**

`string`: PHP type name

### getSchemaMetadata() <span id="method-getSchemaMetadata"></span>

```php
protected function getSchemaMetadata(string $schema, string $type, bool $refresh): array
```

Returns the metadata of the given type for all tables in the given schema.

This method will call a `'getTable' . ucfirst($type)` named method with the table name
and the refresh flag to obtain the metadata.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the metadata. Defaults to empty string, meaning the current or default schema name. |
| `$type` | `string` | Metadata type. |
| `$refresh` | `bool` | Whether to fetch the latest available table metadata. If this is `false`, cached data may be returned if available. |

**Returns**

`array`: Array of metadata.

**Since**

2.0.13

### getTableMetadata() <span id="method-getTableMetadata"></span>

```php
protected function getTableMetadata(string $name, string $type, bool $refresh): mixed
```

Returns the metadata of the given type for the given table.

If there's no metadata in the cache, this method will call
a `'loadTable' . ucfirst($type)` named method with the table name to obtain the metadata.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. The table name may contain schema name if any. Do not quote the table name. |
| `$type` | `string` | Metadata type. |
| `$refresh` | `bool` | Whether to reload the table metadata even if it is found in the cache. |

**Returns**

`mixed`: Metadata.

**Since**

2.0.13

### getTableNameParts() <span id="method-getTableNameParts"></span>

```php
protected function getTableNameParts(string $name): array
```

Splits full table name into parts.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Full table name. |

**Returns**

`array`: Table name parts.

**Since**

2.0.22

### loadTableSchema() <span id="method-loadTableSchema"></span>

```php
abstract protected function loadTableSchema(string $name): yii\db\TableSchema|null
```

Loads the metadata for the specified table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name |

**Returns**

[`TableSchema`](/docs/api/yii/db/tableschema/index.md)`|null`: DBMS-dependent table metadata, `null` if the table does not exist.

### normalizePdoRowKeyCase() <span id="method-normalizePdoRowKeyCase"></span>

```php
protected function normalizePdoRowKeyCase(array $row, bool $multiple): array
```

Changes row's array key case to lower if PDO's one is set to uppercase.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$row` | `array` | Row's array or an array of row's arrays. |
| `$multiple` | `bool` | Whether multiple rows or a single row passed. |

**Returns**

`array`: Normalized row or rows.

**Since**

2.0.13

### resolveTableName() <span id="method-resolveTableName"></span>

```php
protected function resolveTableName(string $name): yii\db\TableSchema
```

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The table name |

**Returns**

[`TableSchema`](/docs/api/yii/db/tableschema/index.md): [`TableSchema`](/docs/api/yii/db/tableschema/index.md) with resolved table, schema, etc. names.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this method is not supported by the DBMS.

**Since**

2.0.13

### setTableMetadata() <span id="method-setTableMetadata"></span>

```php
protected function setTableMetadata(string $name, string $type, mixed $data): mixed
```

Sets the metadata of the given type for the given table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Table name. |
| `$type` | `string` | Metadata type. |
| `$data` | `mixed` | Metadata. |

**Returns**

`mixed`

**Since**

2.0.13