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

Issue Type: Bug Created: 2012-06-21T08:17:19.000+0000 Last Updated: 2012-08-27T20:12:11.000+0000 Status: Closed Fix version(s): Reporter: Denis Felicelli (dionysos) Assignee: Ralph Schindler (ralph) Tags: - Zend\Db

  • Zend_Db
  • zf2

Related issues: Attachments:



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


I'm getting the folloing error:

<pre class="highlight">
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:

<pre class="highlight">
return array(
'db' => array(
    'driver' => 'Sqlsrv',
    'dsn'            => 'sqlsrv:dbname=xxx;hostname=xxx',
    'username'       => 'xxx',
    'password'       => 'xxx',
    'driver_options' => array(

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


Posted by Ralph Schindler (ralph) on 2012-07-11T19:05:35.000+0000

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


Posted by Ralph Schindler (ralph) on 2012-08-14T15:49:18.000+0000

No feedback.

Posted by Jean Rumeau (rumeau) on 2012-08-18T05:23:30.000+0000

Im having this issue too.

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

Im using:

<pre class="highlight">'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.


Posted by Ralph Schindler (ralph) on 2012-08-21T17:47:31.000+0000

I've got a pull request into master that perhaps might fix your issue (

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?

Posted by Jean Rumeau (rumeau) on 2012-08-21T19:20:48.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.