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
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.
-ralph
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:
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
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 (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?
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.