10

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));
}
*/
3
  • Finally I got it Working. 'driver' => 'pdo', 'dsn' => 'sqlsrv:database=payroll;Server=testserver\test', Commented Sep 24, 2012 at 11:04
  • 5
    You should be able to post that as an answer below and accept it. That is acceptable. Commented Jun 24, 2013 at 4:40
  • 5
    Please do that, you're cluttering it as unanswered topic. Commented Oct 9, 2013 at 9:52

2 Answers 2

1

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'
),
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.