Interface Yiisoft\Db\Connection\ConnectionInterface
| Implemented by | Yiisoft\Db\Connection\AbstractConnection, Yiisoft\Db\Debug\ConnectionInterfaceProxy, Yiisoft\Db\Driver\Pdo\AbstractPdoConnection, Yiisoft\Db\Driver\Pdo\PdoConnectionInterface |
|---|
This interface provides methods for establishing a connection to a database, executing SQL statements, and performing other tasks related to interacting with a database.
It allows you to access and manipulate databases in a database-agnostic way, so you can write code that works with different database systems without having to worry about the specific details of each one.
Public Methods
Method Details
Starts a transaction and returns it, creating a new transaction object only if none is currently active.
| public abstract Yiisoft\Db\Transaction\TransactionInterface beginTransaction ( string|null $isolationLevel = null ) | ||
| $isolationLevel | string|null |
The isolation level to use for this transaction. {@see \Yiisoft\Db\Transaction\TransactionInterface::begin()} for details. |
| return | Yiisoft\Db\Transaction\TransactionInterface |
The transaction. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
| throws | Throwable | |
public function beginTransaction(?string $isolationLevel = null): TransactionInterface;
Closes the currently active DB connection.
It does nothing if the connection is already closed.
| public abstract void close ( ) |
public function close(): void;
Creates {@see BatchQueryResultInterface} instance.
| public abstract Yiisoft\Db\Query\BatchQueryResultInterface createBatchQueryResult ( Yiisoft\Db\Query\QueryInterface $query ) | ||
| $query | Yiisoft\Db\Query\QueryInterface |
The query to execute. |
| return | Yiisoft\Db\Query\BatchQueryResultInterface |
The batch query result. |
|---|---|---|
public function createBatchQueryResult(QueryInterface $query): BatchQueryResultInterface;
Creates a command for execution.
| public abstract Yiisoft\Db\Command\CommandInterface createCommand ( string|null $sql = null, array $params = [] ) | ||
| $sql | string|null |
The SQL statement to execute. |
| $params | array |
The parameters to bind to the SQL statement. |
| return | Yiisoft\Db\Command\CommandInterface |
The database command. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
public function createCommand(?string $sql = null, array $params = []): CommandInterface;
Creates {@see QueryInterface} instance.
| public abstract Yiisoft\Db\Query\QueryInterface createQuery ( ) | ||
| return | Yiisoft\Db\Query\QueryInterface |
The query. |
|---|---|---|
public function createQuery(): QueryInterface;
Creates {@see TransactionInterface} instance.
| public abstract Yiisoft\Db\Transaction\TransactionInterface createTransaction ( ) | ||
| return | Yiisoft\Db\Transaction\TransactionInterface |
The transaction. |
|---|---|---|
public function createTransaction(): TransactionInterface;
Returns the column builder class name for the current DB connection.
| public abstract string getColumnBuilderClass ( ) |
public function getColumnBuilderClass(): string;
Returns the column factory for creating column instances.
| public abstract Yiisoft\Db\Schema\Column\ColumnFactoryInterface getColumnFactory ( ) |
public function getColumnFactory(): ColumnFactoryInterface;
Returns the name of the DB driver for the current dsn.
Use this method for information only.
| public abstract string getDriverName ( ) | ||
| return | string |
The name of the DB driver for the current |
|---|---|---|
public function getDriverName(): string;
Returns the ID of the last inserted row or a sequence value.
| public abstract string getLastInsertId ( string|null $sequenceName = null ) | ||
| $sequenceName | string|null |
The name of the sequence object (required by some DBMS). |
| return | string |
The row ID of the last row inserted, or the last value retrieved from the sequence object. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\InvalidCallException | |
public function getLastInsertId(?string $sequenceName = null): string;
Returns the query builder for the current DB connection.
| public abstract Yiisoft\Db\QueryBuilder\QueryBuilderInterface getQueryBuilder ( ) | ||
| return | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
The query builder for the current DB connection. |
|---|---|---|
public function getQueryBuilder(): QueryBuilderInterface;
Returns quoter helper for current DB connection.
| public abstract Yiisoft\Db\Schema\QuoterInterface getQuoter ( ) | ||
| return | Yiisoft\Db\Schema\QuoterInterface |
The quoter helper for the current DB connection. |
|---|---|---|
public function getQuoter(): QuoterInterface;
Returns the schema information for the database opened by this connection.
| public abstract Yiisoft\Db\Schema\SchemaInterface getSchema ( ) | ||
| return | Yiisoft\Db\Schema\SchemaInterface |
The schema information for the database opened by this connection. |
|---|---|---|
public function getSchema(): SchemaInterface;
Returns {@see ServerInfoInterface} instance that provides information about the database server.
| public abstract Yiisoft\Db\Connection\ServerInfoInterface getServerInfo ( ) |
public function getServerInfo(): ServerInfoInterface;
Returns table prefix for current DB connection.
| public abstract string getTablePrefix ( ) | ||
| return | string |
The table prefix for the current DB connection. |
|---|---|---|
public function getTablePrefix(): string;
Obtains the schema information for the named table.
| public abstract Yiisoft\Db\Schema\TableSchemaInterface|null getTableSchema ( string $name, boolean $refresh = false ) | ||
| $name | string |
The table name. |
| $refresh | boolean |
Whether to reload the table schema even if it's found in the cache. |
| return | Yiisoft\Db\Schema\TableSchemaInterface|null |
The schema information for the named table. Null if the named table doesn't exist. |
|---|---|---|
public function getTableSchema(string $name, bool $refresh = false): ?TableSchemaInterface;
Returns the currently active transaction.
| public abstract Yiisoft\Db\Transaction\TransactionInterface|null getTransaction ( ) | ||
| return | Yiisoft\Db\Transaction\TransactionInterface|null |
The currently active transaction. Null if there is no active transaction. |
|---|---|---|
public function getTransaction(): ?TransactionInterface;
Whether the DB connection is active.
| public abstract boolean isActive ( ) | ||
| return | boolean |
Whether the DB connection is active. |
|---|---|---|
public function isActive(): bool;
Whether this DBMS supports savepoint.
| public abstract boolean isSavepointEnabled ( ) | ||
| return | boolean |
Whether this DBMS supports savepoint. |
|---|---|---|
public function isSavepointEnabled(): bool;
Establishes a DB connection.
It does nothing if a DB connection is active.
| public abstract void open ( ) | ||
| throws | Yiisoft\Db\Exception\Exception |
If connection fails. |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException |
If a connection can't be established because of incomplete configuration. |
public function open(): void;
Quotes a value for use in a query.
| public abstract mixed quoteValue ( mixed $value ) | ||
| $value | mixed | |
| return | mixed |
The quoted string. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
public function quoteValue(mixed $value): mixed;
Creates a new {@see Query} instance with the specified columns to be selected.
| public abstract Yiisoft\Db\Query\QueryInterface select ( array|Yiisoft\Db\Expression\ExpressionInterface|scalar $columns = [], string|null $option = null ) | ||
| $columns | array|Yiisoft\Db\Expression\ExpressionInterface|scalar |
The columns to be selected.
Columns can be specified in either a string (for example |
| $option | string|null |
More option that should be appended to the 'SELECT' keyword. For example, in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. |
public function select(
array|bool|float|int|string|ExpressionInterface $columns = [],
?string $option = null,
): QueryInterface;
Whether to enable savepoint.
Note that if the underlying DBMS doesn't support savepoint, setting this property to be true will have no effect.
| public abstract void setEnableSavepoint ( boolean $value ) | ||
| $value | boolean |
Whether to enable savepoint. |
public function setEnableSavepoint(bool $value): void;
Sets the common prefix or suffix for table names.
If a table name is {{%TableName}}, then the percentage
character % will be replaced with this property value.
For example, {{%post}} becomes {{tbl_post}}.
| public abstract void setTablePrefix ( string $value ) | ||
| $value | string |
The common prefix or suffix for table names. |
public function setTablePrefix(string $value): void;
Executes callback provided in a transaction.
| public abstract mixed transaction ( Closure $closure, string|null $isolationLevel = null ) | ||
| $closure | Closure |
A valid PHP callback that performs the job. Accepts connection instance as parameter. |
| $isolationLevel | string|null |
The isolation level to use for this transaction. {@see \Yiisoft\Db\Transaction\TransactionInterface::begin()} for details. |
| return | mixed |
Result of callback function. |
|---|---|---|
| throws | Throwable |
If there is any exception during query. In this case, the transaction will be rolled back. |
public function transaction(Closure $closure, ?string $isolationLevel = null): mixed;
Signup or Login in order to comment.