user1692442
user1692442

Reputation: 101

Zend Framework 2 Microsoft SQL Server 2008 DB connection

I tried out Zend Framework 2 skeleton application and its working fine in Zend Server 5.6 (PHP Version 5.4.0 apache 2.2.21 MYSQL 5.0.10). But i want Zend Framework 2 to connect with MS SQL 2008. I tried the following but it doesn't work and throws exception " An invalid parameter was passed to sqlsrv_execute. "

'db' => array(
    'driver'    => 'sqlsrv',
    'hostname'  => 'testserver\test',
    'Database'  => 'payroll',
    'UID'       => 'sa',
    'PWD'       => '123456'
),

whats wrong with above db array? please suggest me with correct connection string

FYI :

i have tested php 5.4 and MS SQL 2008 connection and it works fine, the following connection was established successfully.

/*
$serverName = "testserver\test"; //serverName\instanceName
$connectionInfo = array( "Database"=>"payroll", "UID"=>"sa", "PWD"=>"123456");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
    echo "---------- Connection established --------------------.<br />";     
    $sql = "select * from users";
    $stmt = sqlsrv_query($conn, $sql);
    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
          echo $row['id'].", ".$row['username']."<br />";
    }    
} else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
*/

Upvotes: 10

Views: 3699

Answers (2)

chahat561
chahat561

Reputation: 91

In your global.php file add the below connection detail:

'db' => array(
        'driver' => 'Sqlsrv',
        'hostname' => 'SERVERNAME',
        'Database' => 'DBNAME',
        'uid' => 'username',
        'pwd' => 'password',
)

To add sqlsrv driver, download it from url : http://www.microsoft.com/en-us/download/details.aspx?id=20098

Add extension in your php ini file like this and then restart apache server:

extension=php_sqlsrv_53_ts.dll

Upvotes: 0

MaxiWheat
MaxiWheat

Reputation: 6261

As you did not technically "answered" your own question, I will do it for you.

Try these connection parameters, they might work using PDO :

'db' => array(
    'driver'    => 'pdo',
    'dsn'       => 'sqlsrv:database=payroll;Server=testserver\test',
    'username'  => 'sa',
    'password'  => '123456'
),

Upvotes: 1

Related Questions