Welcome to Abdul Malik Ikhsan's Blog

Zend Framework 2 : Working with SQL Server

Posted in Tutorial PHP, Zend Framework 2 by samsonasik on March 8, 2013

zf2-zendframework2 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.

7 Responses

Subscribe to comments with RSS.

  1. vinayganeshVinay said, on November 2, 2013 at 2:15 pm

    Hey Abdul, Do you have some kind of a complete example to implement this ? It would be really helpful

  2. Belita said, on April 2, 2015 at 6:50 pm

    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,

  3. minimax said, on April 7, 2017 at 2:49 pm

    Sqlsrv driver is not working. You have to use pdo_sqlsrv

    • samsonasik said, on April 7, 2017 at 3:23 pm

      Thank you, it was long time ago using Sqlsrv driver which was working.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: