ZF2-370: sqlsrv_connect is not called when doing a connection to a Microsoft Sql Server

Description

Hello,

I followed the tutorial of Rob Allen with ZF2 beta 4 when i'm doing

$this->getDatasTable()->fetchAll()

I'm getting the folloing error:


PHP Warning:  sqlsrv_prepare() expects parameter 1 to be resource, null given in C:\inetpub\wwwroot\LinuxWebApp\source\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Sqlsrv\Statement.php on line 153

In config/autoload/global.php I have:


return array(
'db' => array(
    'driver' => 'Sqlsrv',
    'dsn'            => 'sqlsrv:dbname=xxx;hostname=xxx',
    'username'       => 'xxx',
    'password'       => 'xxx',
    'driver_options' => array(
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
    ),
),
);

And it seem that sqlsrv_connect (Zend/Db/Adapter/Driver/Sqlsrv/Connection.php) is not called.

Comments

Are you trying to use the PDO-Sqlsrv extension? or the ext/sqlsrv extension? I can't seem to tell from your code samples.

-ralph

No feedback.

Im having this issue too.

I remove the driver options and im using the ext/sqlsrv extension.

Im using:

'db' => array(
        'driver'        => 'Sqlsrv',
        'database'      => 'xxxxx',
    'hostname'      => 'xxxxxxxxx'
    ),

and the credentials are in a local.php file

I run a debug and it looks like the connect method is never being called, also the $this->sqlsrv property is always null.

Also im using the 2.0.0rc4 version.

Please ask if you need further information.

Thanks

I've got a pull request into master that perhaps might fix your issue (https://github.com/zendframework/zf2/pull/2213).

First, the PDO version of Sqlsrv is currently not officially supported, that is slated for 2.1

The ext/sqlsrv driver is supported. In the mean time, can you paste the actual code that is failing into this issue?

I've just formatted my PC and installed Zend Server CE again, with the sqlsrv extension included and the problem is gone.

I think the problem was the sqlsrv extension i was using, as i installed it manually before.

The strange thing is that the same extension was working well with ZF 1.11.X, the fact is that a clean install of Zend Server CE with sqlsrv native client, provided a working sqlsrv extension.

The code i was using was the code provided in the sample Getting Started with Zend Framework 2 available in the docs, updated to work with the RC4.

I can't provide more feedback because im not sure of the difference between the bundled ext/sqlsrv extension against the SQLSRV extensions provided by Microsoft.