Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Db\TableGateway\AbstractTableGateway won't work with Sqlsrv db adapter #2885

@dkidd

Description

@dkidd

Performing a select using a TableGateway results in the following exception: 'createStatement() only accepts an SQL string or a Sqlsrv resource'

The executeSelect method of Zend\Db\TableGateway\AbstractTableGateway includes the following line:

// prepare and execute
$statement = $this->sql->prepareStatementForSqlObject($select);

Which calls the prepareStatementForSqlObject method of Zend\Db\Sql\Sql:

public function prepareStatementForSqlObject(PreparableSqlInterface $sqlObject, StatementInterface $statement = null)
    {
        $statement = ($statement) ?: $this->adapter->createStatement();
        ...

Since AbstractTableGateway doesn't pass a second parameter, $statement will always be null. But calling the createStatement method of Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv without an argument throws the exception given above.

public function createStatement($sqlOrResource = null)
    {
        $statement = clone $this->statementPrototype;
        if (is_string($sqlOrResource)) {
            $statement->setSql($sqlOrResource);
            if (!$this->connection->isConnected()) {
                $this->connection->connect();
            }
            $statement->initialize($this->connection->getResource());
        } elseif (is_resource($sqlOrResource)) {
            $statement->initialize($sqlOrResource); // will check the resource type
        } else {
            throw new Exception\InvalidArgumentException('createStatement() only accepts an SQL string or a Sqlsrv resource');
        }
        return $statement;
}

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions