Zend Framework 2 : Working with SQL Server
In some situation, work on windows environment is not as easy as you’ve imagine. SQL Server is a powerfull database platform with complex features and it means complex requirements too. In this post, I will show you step by step to work with.
1. Install Your SQL Server
2. Download SqlSrv extension for PHP, you can download from http://www.microsoft.com/en-us/download/details.aspx?id=20098 , I’m prefer using *V30.EXE
3. Run the executable file, and you will find an input which show message “Please type the location where you want to place the extacted files. : “, fill in with your php ext directory.
4. Download Microsoft® SQL Server® 2012 Native Client here : http://www.microsoft.com/en-us/download/details.aspx?id=29065 and install the lib. ( choose between X64 Package (sqlncli.msi) or X86 Package (sqlncli.msi) ).
5. Register SqlSrv extension into php extension in php.ini
// or 54 based on your php version extension=php_sqlsrv_53_ts.dll
6. Restart your web server
7. Configure your db adapter
'db' => array( 'driver' => 'Sqlsrv', 'server' => 'ACER-PC', 'Database' => 'YourDB', 'USER' => 'sa', //if you're using sa 'password' => 'yourpassword' );
Done !, let’s run.
Note : It’s work for SQL Server 2008.
Hey Abdul, Do you have some kind of a complete example to implement this ? It would be really helpful
An exception was raised while creating “Album\Model\AlbumTable”; no instance returned
This is the error that i am getting if i try to use akrabat’s example. Any idea why ?
read the docs http://zf2.readthedocs.org/en/latest/user-guide/overview.html
I have this problem
No connection could be made because the target machine actively refused it.
i’m using Doctrine with ZF2 to connect.
// Alternative DB connection
‘orm_alternative’ => array(
‘driverClass’ => ‘Doctrine\DBAL\Driver\PDOSqlsrv\Driver’,
‘params’ => array(
‘host’ => ‘10.10.0.25’,
‘user’ => ‘sa’,
‘port’ => ‘1433’,
‘password’ => ‘12345678’,
‘dbname’ => ‘MSSQL_TESTE’,
),
),
the extension pdo_sqlsrv its ok,
sorry, didn’t try at doctrine yet
Sqlsrv driver is not working. You have to use pdo_sqlsrv
Thank you, it was long time ago using Sqlsrv driver which was working.