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));
}
*/
Connect to a SQL Server instanceStart SQL Server Management Studio. The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine. For Server type, select Database Engine (usually the default option).
Running MS SQL Queries from PHP See the full list of MS SQL functions in PHP at php.net. The following script is an example of an MS SQL SELECT query run from PHP. <? php $query ="SELECT col1,col2 FROM tablename"; $result =mssql_query($query); while ( $record = mssql_fetch_array($result) ) { echo $record["col1"] .
The Microsoft Drivers for PHP for SQL Server enable integration with SQL Server for PHP applications. The drivers are PHP extensions that allow the reading and writing of SQL Server data from within PHP scripts.
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'
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With