0 follower

Abstract Class Yiisoft\Db\Driver\Pdo\AbstractPdoCommand

InheritanceYiisoft\Db\Driver\Pdo\AbstractPdoCommand » Yiisoft\Db\Command\AbstractCommand
ImplementsPsr\Log\LoggerAwareInterface, Yiisoft\Db\Command\CommandInterface, Yiisoft\Db\Driver\Pdo\PdoCommandInterface, Yiisoft\Db\Profiler\ProfilerAwareInterface
Uses TraitsPsr\Log\LoggerAwareTrait, Yiisoft\Db\Profiler\ProfilerAwareTrait

Represents a database command that can be executed using a PDO (PHP Data Object) database connection.

It's an abstract class that provides a common interface for building and executing various types of statements such as {@see \Yiisoft\Db\Driver\Pdo\cancel()}, {@see \Yiisoft\Db\Driver\Pdo\execute()}, {@see \Yiisoft\Db\Driver\Pdo\insert()}, {@see \Yiisoft\Db\Driver\Pdo\update()}, {@see \Yiisoft\Db\Driver\Pdo\delete()}, etc., using a PDO connection.

It also provides methods for binding parameter values and retrieving query results.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
addCheck() Yiisoft\Db\Command\AbstractCommand
addColumn() Yiisoft\Db\Command\AbstractCommand
addCommentOnColumn() Yiisoft\Db\Command\AbstractCommand
addCommentOnTable() Yiisoft\Db\Command\AbstractCommand
addDefaultValue() Yiisoft\Db\Command\AbstractCommand
addForeignKey() Yiisoft\Db\Command\AbstractCommand
addPrimaryKey() Yiisoft\Db\Command\AbstractCommand
addUnique() Yiisoft\Db\Command\AbstractCommand
alterColumn() Yiisoft\Db\Command\AbstractCommand
bindParam() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
bindValue() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
bindValues() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
cancel() This method mainly sets {@see pdoStatement} to be null. Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
checkIntegrity() Yiisoft\Db\Command\AbstractCommand
createIndex() Yiisoft\Db\Command\AbstractCommand
createTable() Yiisoft\Db\Command\AbstractCommand
createView() Yiisoft\Db\Command\AbstractCommand
delete() Yiisoft\Db\Command\AbstractCommand
dropCheck() Yiisoft\Db\Command\AbstractCommand
dropColumn() Yiisoft\Db\Command\AbstractCommand
dropCommentFromColumn() Yiisoft\Db\Command\AbstractCommand
dropCommentFromTable() Yiisoft\Db\Command\AbstractCommand
dropDefaultValue() Yiisoft\Db\Command\AbstractCommand
dropForeignKey() Yiisoft\Db\Command\AbstractCommand
dropIndex() Yiisoft\Db\Command\AbstractCommand
dropPrimaryKey() Yiisoft\Db\Command\AbstractCommand
dropTable() Yiisoft\Db\Command\AbstractCommand
dropUnique() Yiisoft\Db\Command\AbstractCommand
dropView() Yiisoft\Db\Command\AbstractCommand
execute() Yiisoft\Db\Command\AbstractCommand
getParams() Yiisoft\Db\Command\AbstractCommand
getPdoStatement() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
getRawSql() Yiisoft\Db\Command\AbstractCommand
getSql() Yiisoft\Db\Command\AbstractCommand
insert() Yiisoft\Db\Command\AbstractCommand
insertBatch() Yiisoft\Db\Command\AbstractCommand
insertReturningPks() Yiisoft\Db\Command\AbstractCommand
prepare() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
query() Yiisoft\Db\Command\AbstractCommand
queryAll() Yiisoft\Db\Command\AbstractCommand
queryColumn() Yiisoft\Db\Command\AbstractCommand
queryOne() Yiisoft\Db\Command\AbstractCommand
queryScalar() Yiisoft\Db\Command\AbstractCommand
renameColumn() Yiisoft\Db\Command\AbstractCommand
renameTable() Yiisoft\Db\Command\AbstractCommand
resetSequence() Yiisoft\Db\Command\AbstractCommand
setProfiler() Yiisoft\Db\Profiler\ProfilerAwareTrait
setRawSql() Yiisoft\Db\Command\AbstractCommand
setRetryHandler() Yiisoft\Db\Command\AbstractCommand
setSql() Yiisoft\Db\Command\AbstractCommand
showDatabases() List all database names in the current connection. Yiisoft\Db\Command\CommandInterface
truncateTable() Yiisoft\Db\Command\AbstractCommand
update() Yiisoft\Db\Command\AbstractCommand
upsert() Yiisoft\Db\Command\AbstractCommand
upsertReturning() Yiisoft\Db\Command\AbstractCommand
upsertReturningPks() Yiisoft\Db\Command\AbstractCommand
withDbTypecasting() Yiisoft\Db\Command\AbstractCommand
withPhpTypecasting() Yiisoft\Db\Command\AbstractCommand
withTypecasting() Yiisoft\Db\Command\AbstractCommand

Protected Methods

Hide inherited methods

Method Description Defined By
bindPendingParams() Binds pending parameters registered via {@see bindValue()} and {@see bindValues()}. Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
getQueryBuilder() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
getQueryMode() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
internalExecute() A wrapper around {@see pdoStatementExecute()} to support transactions and retry handlers. Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
internalGetQueryResult() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
is() Check if the value has a given flag. Yiisoft\Db\Command\AbstractCommand
pdoStatementExecute() Executes a prepared statement. Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
queryInternal() Yiisoft\Db\Driver\Pdo\AbstractPdoCommand
requireTableSchemaRefresh() Marks a specified table schema to be refreshed after command execution. Yiisoft\Db\Command\AbstractCommand
reset() Resets the command object, so it can be reused to build another SQL statement. Yiisoft\Db\Command\AbstractCommand

Constants

Hide inherited constants

Constant Value Description Defined By
QUERY_MODE_ALL 4 Command in this query mode returns all rows of selected data. Yiisoft\Db\Command\AbstractCommand
QUERY_MODE_COLUMN 8 Command in this query mode returns all rows with the first column of selected data. Yiisoft\Db\Command\AbstractCommand
QUERY_MODE_CURSOR 16 Command in this query mode returns {@see DataReaderInterface}, an abstraction for database cursor for selected data. Yiisoft\Db\Command\AbstractCommand
QUERY_MODE_EXECUTE 1 Command in this query mode returns count of affected rows. Yiisoft\Db\Command\AbstractCommand
QUERY_MODE_ROW 2 Command in this query mode returns the first row of selected data. Yiisoft\Db\Command\AbstractCommand
QUERY_MODE_SCALAR 32 Command in this query mode returns the first column in the first row of the query result Yiisoft\Db\Command\AbstractCommand

Property Details

Hide inherited properties

$db protected property
$pdoStatement protected property

Represents a prepared statement and, after the statement is executed, an associated result set.

protected PDOStatement|null $pdoStatement null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Db\Driver\Pdo\PdoConnectionInterface $db )
$db Yiisoft\Db\Driver\Pdo\PdoConnectionInterface

The PDO database connection to use.

                public function __construct(PdoConnectionInterface $db)
{
    parent::__construct($db);
}

            
addCheck() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addCheck ( string $table, string $name, string $expression )
$table string
$name string
$expression string

                public function addCheck(string $table, string $name, string $expression): static
{
    $sql = $this->getQueryBuilder()->addCheck($table, $name, $expression);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string
$column string
$type Yiisoft\Db\Schema\Column\ColumnInterface|string

                public function addColumn(string $table, string $column, ColumnInterface|string $type): static
{
    $sql = $this->getQueryBuilder()->addColumn($table, $column, $type);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addCommentOnColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addCommentOnColumn ( string $table, string $column, string $comment )
$table string
$column string
$comment string

                public function addCommentOnColumn(string $table, string $column, string $comment): static
{
    $sql = $this->getQueryBuilder()->addCommentOnColumn($table, $column, $comment);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addCommentOnTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addCommentOnTable ( string $table, string $comment )
$table string
$comment string

                public function addCommentOnTable(string $table, string $comment): static
{
    $sql = $this->getQueryBuilder()->addCommentOnTable($table, $comment);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addDefaultValue() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addDefaultValue ( string $table, string $name, string $column, mixed $value )
$table string
$name string
$column string
$value mixed

                public function addDefaultValue(string $table, string $name, string $column, mixed $value): static
{
    $sql = $this->getQueryBuilder()->addDefaultValue($table, $name, $column, $value);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addForeignKey() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete null, string|null $update null )
$table string
$name string
$columns array|string
$referenceTable string
$referenceColumns array|string
$delete string|null
$update string|null

                public function addForeignKey(
    string $table,
    string $name,
    array|string $columns,
    string $referenceTable,
    array|string $referenceColumns,
    ?string $delete = null,
    ?string $update = null,
): static {
    $sql = $this->getQueryBuilder()->addForeignKey(
        $table,
        $name,
        $columns,
        $referenceTable,
        $referenceColumns,
        $delete,
        $update,
    );
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addPrimaryKey() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addPrimaryKey ( string $table, string $name, array|string $columns )
$table string
$name string
$columns array|string

                public function addPrimaryKey(string $table, string $name, array|string $columns): static
{
    $sql = $this->getQueryBuilder()->addPrimaryKey($table, $name, $columns);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
addUnique() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand addUnique ( string $table, string $name, array|string $columns )
$table string
$name string
$columns array|string

                public function addUnique(string $table, string $name, array|string $columns): static
{
    $sql = $this->getQueryBuilder()->addUnique($table, $name, $columns);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
alterColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand alterColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string
$column string
$type Yiisoft\Db\Schema\Column\ColumnInterface|string

                public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
    $sql = $this->getQueryBuilder()->alterColumn($table, $column, $type);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
bindParam() public method

public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand bindParam ( integer|string $name, mixed &$value, integer|null $dataType null, integer|null $length null, mixed $driverOptions null )
$name integer|string
$value mixed
$dataType integer|null
$length integer|null
$driverOptions mixed

                public function bindParam(
    int|string $name,
    mixed &$value,
    ?int $dataType = null,
    ?int $length = null,
    mixed $driverOptions = null,
): static {
    $this->prepare();
    if ($dataType === null) {
        $dataType = $this->db->getSchema()->getDataType($value);
    }
    if ($length === null) {
        $this->pdoStatement?->bindParam($name, $value, $dataType);
    } elseif ($driverOptions === null) {
        $this->pdoStatement?->bindParam($name, $value, $dataType, $length);
    } else {
        $this->pdoStatement?->bindParam($name, $value, $dataType, $length, $driverOptions);
    }
    return $this;
}

            
bindPendingParams() protected method

Binds pending parameters registered via {@see bindValue()} and {@see bindValues()}.

Note that this method requires an active {@see \Yiisoft\Db\Driver\Pdo\pdoStatement}.

protected void bindPendingParams ( )

                protected function bindPendingParams(): void
{
    foreach ($this->params as $name => $value) {
        $this->pdoStatement?->bindValue($name, $value->value, $value->type);
    }
}

            
bindValue() public method

public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand bindValue ( integer|string $name, mixed $value, integer|null $dataType null )
$name integer|string
$value mixed
$dataType integer|null

                public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static
{
    if ($dataType === null) {
        $dataType = $this->db->getSchema()->getDataType($value);
    }
    $this->params[$name] = new Param($value, $dataType);
    return $this;
}

            
bindValues() public method

public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand bindValues ( array $values )
$values array

                public function bindValues(array $values): static
{
    if (empty($values)) {
        return $this;
    }
    /**
     * @psalm-var array<string, int>|Param|int $value
     */
    foreach ($values as $name => $value) {
        if ($value instanceof Param) {
            $this->params[$name] = $value;
        } else {
            $type = $this->db->getSchema()->getDataType($value);
            $this->params[$name] = new Param($value, $type);
        }
    }
    return $this;
}

            
cancel() public method

This method mainly sets {@see pdoStatement} to be null.

public void cancel ( )

                public function cancel(): void
{
    $this->pdoStatement = null;
}

            
checkIntegrity() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand checkIntegrity ( string $schema, string $table, boolean $check true )
$schema string
$table string
$check boolean

                public function checkIntegrity(string $schema, string $table, bool $check = true): static
{
    $sql = $this->getQueryBuilder()->checkIntegrity($schema, $table, $check);
    return $this->setSql($sql);
}

            
createIndex() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand createIndex ( string $table, string $name, array|string $columns, string|null $indexType null, string|null $indexMethod null )
$table string
$name string
$columns array|string
$indexType string|null
$indexMethod string|null

                public function createIndex(
    string $table,
    string $name,
    array|string $columns,
    ?string $indexType = null,
    ?string $indexMethod = null,
): static {
    $sql = $this->getQueryBuilder()->createIndex($table, $name, $columns, $indexType, $indexMethod);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
createTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand createTable ( string $table, array $columns, string|null $options null )
$table string
$columns array
$options string|null

                public function createTable(string $table, array $columns, ?string $options = null): static
{
    $sql = $this->getQueryBuilder()->createTable($table, $columns, $options);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
createView() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand createView ( string $viewName, Yiisoft\Db\Query\QueryInterface|string $subQuery )
$viewName string
$subQuery Yiisoft\Db\Query\QueryInterface|string

                public function createView(string $viewName, QueryInterface|string $subQuery): static
{
    $sql = $this->getQueryBuilder()->createView($viewName, $subQuery);
    return $this->setSql($sql)->requireTableSchemaRefresh($viewName);
}

            
delete() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand delete ( string $table, array|string $condition '', array $params = [] )
$table string
$condition array|string
$params array

                public function delete(string $table, array|string $condition = '', array $params = []): static
{
    $sql = $this->getQueryBuilder()->delete($table, $condition, $params);
    return $this->setSql($sql)->bindValues($params);
}

            
dropCheck() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropCheck ( string $table, string $name )
$table string
$name string

                public function dropCheck(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropCheck($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropColumn ( string $table, string $column )
$table string
$column string

                public function dropColumn(string $table, string $column): static
{
    $sql = $this->getQueryBuilder()->dropColumn($table, $column);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropCommentFromColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropCommentFromColumn ( string $table, string $column )
$table string
$column string

                public function dropCommentFromColumn(string $table, string $column): static
{
    $sql = $this->getQueryBuilder()->dropCommentFromColumn($table, $column);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropCommentFromTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropCommentFromTable ( string $table )
$table string

                public function dropCommentFromTable(string $table): static
{
    $sql = $this->getQueryBuilder()->dropCommentFromTable($table);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropDefaultValue() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropDefaultValue ( string $table, string $name )
$table string
$name string

                public function dropDefaultValue(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropDefaultValue($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropForeignKey() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropForeignKey ( string $table, string $name )
$table string
$name string

                public function dropForeignKey(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropForeignKey($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropIndex() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropIndex ( string $table, string $name )
$table string
$name string

                public function dropIndex(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropIndex($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropPrimaryKey() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropPrimaryKey ( string $table, string $name )
$table string
$name string

                public function dropPrimaryKey(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropPrimaryKey($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropTable ( string $table, boolean $ifExists false, boolean $cascade false )
$table string
$ifExists boolean
$cascade boolean

                public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): static
{
    $sql = $this->getQueryBuilder()->dropTable($table, $ifExists, $cascade);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropUnique() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropUnique ( string $table, string $name )
$table string
$name string

                public function dropUnique(string $table, string $name): static
{
    $sql = $this->getQueryBuilder()->dropUnique($table, $name);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
dropView() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand dropView ( string $viewName )
$viewName string

                public function dropView(string $viewName): static
{
    $sql = $this->getQueryBuilder()->dropView($viewName);
    return $this->setSql($sql)->requireTableSchemaRefresh($viewName);
}

            
execute() public method
public integer execute ( )

                public function execute(): int
{
    $sql = $this->getSql();
    if ($sql === '') {
        return 0;
    }
    /** @var bool|int $execute */
    $execute = $this->queryInternal(self::QUERY_MODE_EXECUTE);
    return is_int($execute) ? $execute : 0;
}

            
getParams() public method
public array getParams ( boolean $asValues true )
$asValues boolean

                public function getParams(bool $asValues = true): array
{
    if (!$asValues) {
        return $this->params;
    }
    $buildParams = [];
    foreach ($this->params as $name => $value) {
        $buildParams[$name] = $value->value;
    }
    return $buildParams;
}

            
getPdoStatement() public method

public PDOStatement|null getPdoStatement ( )

                public function getPdoStatement(): ?PDOStatement
{
    return $this->pdoStatement;
}

            
getQueryBuilder() protected method

protected Yiisoft\Db\QueryBuilder\QueryBuilderInterface getQueryBuilder ( )

                protected function getQueryBuilder(): QueryBuilderInterface
{
    return $this->db->getQueryBuilder()->withTypecasting($this->dbTypecasting);
}

            
getQueryMode() protected method

protected string getQueryMode ( integer $queryMode )
$queryMode integer

                protected function getQueryMode(int $queryMode): string
{
    return match ($queryMode) {
        self::QUERY_MODE_EXECUTE => 'execute',
        self::QUERY_MODE_ROW => 'queryOne',
        self::QUERY_MODE_ALL => 'queryAll',
        self::QUERY_MODE_COLUMN => 'queryColumn',
        self::QUERY_MODE_CURSOR => 'query',
        self::QUERY_MODE_SCALAR => 'queryScalar',
        self::QUERY_MODE_ROW | self::QUERY_MODE_EXECUTE => 'insertReturningPks',
    };
}

            
getRawSql() public method
public string getRawSql ( )

                public function getRawSql(): string
{
    if (empty($this->params)) {
        return $this->sql;
    }
    $queryBuilder = $this->getQueryBuilder();
    $params = array_map($queryBuilder->prepareParam(...), $this->params);
    if (!isset($params[0])) {
        return $queryBuilder->replacePlaceholders($this->sql, $params);
    }
    // Support unnamed placeholders should be dropped
    $sql = '';
    foreach (explode('?', $this->sql) as $i => $part) {
        $sql .= $part . ($params[$i] ?? '');
    }
    return $sql;
}

            
getSql() public method
public string getSql ( )

                public function getSql(): string
{
    return $this->sql;
}

            
insert() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand insert ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns )
$table string
$columns array|Yiisoft\Db\Query\QueryInterface

                public function insert(string $table, array|QueryInterface $columns): static
{
    $params = [];
    $sql = $this->getQueryBuilder()->insert($table, $columns, $params);
    return $this->setSql($sql)->bindValues($params);
}

            
insertBatch() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand insertBatch ( string $table, iterable $rows, array $columns = [] )
$table string
$rows iterable
$columns array

                public function insertBatch(string $table, iterable $rows, array $columns = []): static
{
    $table = $this->getQueryBuilder()->getQuoter()->getRawTableName($table);
    $params = [];
    $sql = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $params);
    $this->setRawSql($sql);
    $this->bindValues($params);
    return $this;
}

            
insertReturningPks() public method
public array insertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns )
$table string
$columns array|Yiisoft\Db\Query\QueryInterface

                public function insertReturningPks(string $table, array|QueryInterface $columns): array
{
    if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) {
        $this->insert($table, $columns)->execute();
        return [];
    }
    $params = [];
    $sql = $this->getQueryBuilder()->insertReturningPks($table, $columns, $params);
    $this->setSql($sql)->bindValues($params);
    /** @psalm-var array<string, mixed> */
    return $this->queryInternal(self::QUERY_MODE_ROW | self::QUERY_MODE_EXECUTE);
}

            
internalExecute() protected method

A wrapper around {@see pdoStatementExecute()} to support transactions and retry handlers.

protected void internalExecute ( )
throws Yiisoft\Db\Exception\Exception

                protected function internalExecute(): void
{
    for ($attempt = 0; ; ++$attempt) {
        try {
            $this->pdoStatementExecute();
            break;
        } catch (PDOException $e) {
            $rawSql ??= $this->getRawSql();
            $e = (new ConvertException($e, $rawSql))->run();
            if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
                throw $e;
            }
        }
    }
}

            
internalGetQueryResult() protected method

protected mixed internalGetQueryResult ( integer $queryMode )
$queryMode integer
throws InvalidArgumentException

                protected function internalGetQueryResult(int $queryMode): mixed
{
    if ($queryMode === self::QUERY_MODE_CURSOR) {
        /** @psalm-suppress PossiblyNullArgument */
        $dataReader = new PdoDataReader($this->pdoStatement);
        if ($this->phpTypecasting && ($row = $dataReader->current()) !== false) {
            /** @psalm-var array<string,mixed> $row */
            $dataReader->typecastColumns($this->getResultColumns(array_keys($row)));
        }
        return $dataReader;
    }
    if ($queryMode === self::QUERY_MODE_EXECUTE) {
        return $this->pdoStatement?->rowCount() ?? 0;
    }
    if ($this->is($queryMode, self::QUERY_MODE_ROW)) {
        /** @psalm-var array<string,mixed>|false $result */
        $result = $this->pdoStatement?->fetch(PDO::FETCH_ASSOC);
        if ($this->phpTypecasting && $result !== false) {
            $result = $this->phpTypecastRows([$result])[0];
        }
    } elseif ($this->is($queryMode, self::QUERY_MODE_SCALAR)) {
        $result = $this->pdoStatement?->fetchColumn();
        if (
            $this->phpTypecasting
            && $result !== false
            && ($column = $this->getResultColumn(0)) !== null
        ) {
            $result = $column->phpTypecast($result);
        }
    } elseif ($this->is($queryMode, self::QUERY_MODE_COLUMN)) {
        $result = $this->pdoStatement?->fetchAll(PDO::FETCH_COLUMN);
        if (
            $this->phpTypecasting
            && !empty($result)
            && ($column = $this->getResultColumn(0)) !== null
        ) {
            $result = array_map($column->phpTypecast(...), $result);
        }
    } elseif ($this->is($queryMode, self::QUERY_MODE_ALL)) {
        $result = $this->pdoStatement?->fetchAll(PDO::FETCH_ASSOC);
        if ($this->phpTypecasting && !empty($result)) {
            $result = $this->phpTypecastRows($result);
        }
    } else {
        throw new InvalidArgumentException("Unknown query mode '$queryMode'");
    }
    $this->pdoStatement?->closeCursor();
    return $result;
}

            
is() protected method

Defined in: Yiisoft\Db\Command\AbstractCommand::is()

Check if the value has a given flag.

protected boolean is ( integer $value, integer $flag )
$value integer

Flags value to check.

$flag integer

Flag to look for in the value.

return boolean

Whether the value has a given flag.

                protected function is(int $value, int $flag): bool
{
    return ($value & $flag) === $flag;
}

            
pdoStatementExecute() protected method

Executes a prepared statement.

protected void pdoStatementExecute ( )
throws PDOException

                protected function pdoStatementExecute(): void
{
    $this->pdoStatement?->execute();
}

            
prepare() public method

public void prepare ( boolean|null $forRead null )
$forRead boolean|null

                public function prepare(?bool $forRead = null): void
{
    if (isset($this->pdoStatement)) {
        $this->bindPendingParams();
        return;
    }
    $sql = $this->getSql();
    /**
     * If SQL is empty, there will be {@see \ValueError} on prepare pdoStatement.
     *
     * @link https://php.watch/versions/8.0/ValueError
     */
    if ($sql === '') {
        return;
    }
    $pdo = $this->db->getActivePdo();
    try {
        $this->pdoStatement = $pdo->prepare($sql);
        $this->bindPendingParams();
    } catch (PDOException $e) {
        $message = $e->getMessage() . "\nFailed to prepare SQL: $sql";
        $errorInfo = $e->errorInfo ?? null;
        throw new Exception($message, $errorInfo, $e);
    }
}

            
query() public method
public Yiisoft\Db\Query\DataReaderInterface query ( )

                public function query(): DataReaderInterface
{
    /** @var DataReaderInterface */
    return $this->queryInternal(self::QUERY_MODE_CURSOR);
}

            
queryAll() public method
public array queryAll ( )

                public function queryAll(): array
{
    /** @psalm-var list<array>|null $results */
    $results = $this->queryInternal(self::QUERY_MODE_ALL);
    return $results ?? [];
}

            
queryColumn() public method
public array queryColumn ( )

                public function queryColumn(): array
{
    $results = $this->queryInternal(self::QUERY_MODE_COLUMN);
    return is_array($results) ? $results : [];
}

            
queryInternal() protected method

protected mixed queryInternal ( integer $queryMode )
$queryMode integer

                protected function queryInternal(int $queryMode): mixed
{
    $logCategory = self::class . '::' . $this->getQueryMode($queryMode);
    $this->logger?->log(LogLevel::INFO, $rawSql = $this->getRawSql(), [$logCategory, 'type' => LogType::QUERY]);
    $queryContext = new CommandContext(__METHOD__, $logCategory, $this->getSql(), $this->getParams());
    /** @var string|null $rawSql */
    $this->profiler?->begin($rawSql ??= $this->getRawSql(), $queryContext);
    /** @var string $rawSql */
    try {
        $result = parent::queryInternal($queryMode);
    } catch (Throwable $e) {
        $this->profiler?->end($rawSql, $queryContext->setException($e));
        throw $e;
    }
    $this->profiler?->end($rawSql, $queryContext);
    return $result;
}

            
queryOne() public method
public array|null queryOne ( )

                public function queryOne(): ?array
{
    /** @psalm-var array<string,mixed>|false $results */
    $results = $this->queryInternal(self::QUERY_MODE_ROW);
    return is_array($results) ? $results : null;
}

            
queryScalar() public method
public boolean|string|integer|float|null queryScalar ( )

                public function queryScalar(): bool|string|int|float|null
{
    $result = $this->queryInternal(self::QUERY_MODE_SCALAR);
    if (is_resource($result) && get_resource_type($result) === 'stream') {
        return stream_get_contents($result);
    }
    return is_scalar($result) ? $result : null;
}

            
renameColumn() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand renameColumn ( string $table, string $oldName, string $newName )
$table string
$oldName string
$newName string

                public function renameColumn(string $table, string $oldName, string $newName): static
{
    $sql = $this->getQueryBuilder()->renameColumn($table, $oldName, $newName);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
renameTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand renameTable ( string $table, string $newName )
$table string
$newName string

                public function renameTable(string $table, string $newName): static
{
    $sql = $this->getQueryBuilder()->renameTable($table, $newName);
    return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

            
requireTableSchemaRefresh() protected method

Defined in: Yiisoft\Db\Command\AbstractCommand::requireTableSchemaRefresh()

Marks a specified table schema to be refreshed after command execution.

protected Yiisoft\Db\Driver\Pdo\AbstractPdoCommand requireTableSchemaRefresh ( string $name )
$name string

Name of the table, which schema should be refreshed.

                protected function requireTableSchemaRefresh(string $name): static
{
    $this->refreshTableName = $name;
    return $this;
}

            
reset() protected method

Defined in: Yiisoft\Db\Command\AbstractCommand::reset()

Resets the command object, so it can be reused to build another SQL statement.

protected void reset ( )

                protected function reset(): void
{
    $this->sql = '';
    $this->params = [];
    $this->refreshTableName = null;
}

            
resetSequence() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand resetSequence ( string $table, integer|string|null $value null )
$table string
$value integer|string|null

                public function resetSequence(string $table, int|string|null $value = null): static
{
    $sql = $this->getQueryBuilder()->resetSequence($table, $value);
    return $this->setSql($sql);
}

            
setProfiler() public method
public void setProfiler ( Yiisoft\Db\Profiler\ProfilerInterface|null $profiler )
$profiler Yiisoft\Db\Profiler\ProfilerInterface|null

                public function setProfiler(?ProfilerInterface $profiler): void
{
    $this->profiler = $profiler;
}

            
setRawSql() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand setRawSql ( string $sql )
$sql string

                public function setRawSql(string $sql): static
{
    if ($sql !== $this->sql) {
        $this->cancel();
        $this->reset();
        $this->sql = $sql;
    }
    return $this;
}

            
setRetryHandler() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand setRetryHandler ( Closure|null $handler )
$handler Closure|null

                public function setRetryHandler(?Closure $handler): static
{
    $this->retryHandler = $handler;
    return $this;
}

            
setSql() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand setSql ( string $sql )
$sql string

                public function setSql(string $sql): static
{
    $this->cancel();
    $this->reset();
    $this->sql = $this->getQueryBuilder()->getQuoter()->quoteSql($sql);
    return $this;
}

            
showDatabases() public abstract method

Defined in: Yiisoft\Db\Command\CommandInterface::showDatabases()

List all database names in the current connection.

public abstract array showDatabases ( )

                public function showDatabases(): array;

            
truncateTable() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand truncateTable ( string $table )
$table string

                public function truncateTable(string $table): static
{
    $sql = $this->getQueryBuilder()->truncateTable($table);
    return $this->setSql($sql);
}

            
update() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand update ( string $table, array $columns, array|Yiisoft\Db\Expression\ExpressionInterface|string $condition '', array|Yiisoft\Db\Expression\ExpressionInterface|string|null $from null, array $params = [] )
$table string
$columns array
$condition array|Yiisoft\Db\Expression\ExpressionInterface|string
$from array|Yiisoft\Db\Expression\ExpressionInterface|string|null
$params array

                public function update(
    string $table,
    array $columns,
    array|ExpressionInterface|string $condition = '',
    array|ExpressionInterface|string|null $from = null,
    array $params = [],
): static {
    $sql = $this->getQueryBuilder()->update($table, $columns, $condition, $from, $params);
    return $this->setSql($sql)->bindValues($params);
}

            
upsert() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand upsert ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true )
$table string
$insertColumns array|Yiisoft\Db\Query\QueryInterface
$updateColumns array|boolean

                public function upsert(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
): static {
    $params = [];
    $sql = $this->getQueryBuilder()->upsert($table, $insertColumns, $updateColumns, $params);
    return $this->setSql($sql)->bindValues($params);
}

            
upsertReturning() public method
public array upsertReturning ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true, array|null $returnColumns null )
$table string
$insertColumns array|Yiisoft\Db\Query\QueryInterface
$updateColumns array|boolean
$returnColumns array|null

                public function upsertReturning(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
    ?array $returnColumns = null,
): array {
    if ($returnColumns === []) {
        $this->upsert($table, $insertColumns, $updateColumns)->execute();
        return [];
    }
    $params = [];
    $sql = $this->getQueryBuilder()
        ->upsertReturning($table, $insertColumns, $updateColumns, $returnColumns, $params);
    $this->setSql($sql)->bindValues($params);
    /** @psalm-var array<string, mixed> */
    return $this->queryInternal(self::QUERY_MODE_ROW | self::QUERY_MODE_EXECUTE);
}

            
upsertReturningPks() public method
public array upsertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true )
$table string
$insertColumns array|Yiisoft\Db\Query\QueryInterface
$updateColumns array|boolean

                public function upsertReturningPks(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
): array {
    $primaryKeys = $this->db->getSchema()->getTableSchema($table)?->getPrimaryKey() ?? [];
    return $this->upsertReturning($table, $insertColumns, $updateColumns, $primaryKeys);
}

            
withDbTypecasting() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand withDbTypecasting ( boolean $dbTypecasting true )
$dbTypecasting boolean

                public function withDbTypecasting(bool $dbTypecasting = true): static
{
    $new = clone $this;
    $new->dbTypecasting = $dbTypecasting;
    return $new;
}

            
withPhpTypecasting() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand withPhpTypecasting ( boolean $phpTypecasting true )
$phpTypecasting boolean

                public function withPhpTypecasting(bool $phpTypecasting = true): static
{
    $new = clone $this;
    $new->phpTypecasting = $phpTypecasting;
    return $new;
}

            
withTypecasting() public method
public Yiisoft\Db\Driver\Pdo\AbstractPdoCommand withTypecasting ( boolean $typecasting true )
$typecasting boolean

                public function withTypecasting(bool $typecasting = true): static
{
    $new = clone $this;
    $new->dbTypecasting = $typecasting;
    $new->phpTypecasting = $typecasting;
    return $new;
}