Connection could not be established.
Not able to connect and execute queries from php. I’m new in php. so please help.
I’m getting this…
Array ( [0] => Array ( [0] => HY000 [SQLSTATE] => HY000 [1] => -2146893042 [code] => -2146893042 [2] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: No credentials are available in the security package [message] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: No credentials are available in the security package ) [1] => Array ( [0] => HY000 [SQLSTATE] => HY000 [1] => -2146893042 [code] => -2146893042 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot generate SSPI context [message] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot generate SSPI context ) [2] => Array ( [0] => HY000 [SQLSTATE] => HY000 [1] => -2146893042 [code] => -2146893042 [2] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: No credentials are available in the security package [message] => [Microsoft][ODBC Driver 17 for SQL Server]SQL Server Network Interfaces: No credentials are available in the security package ) [3] => Array ( [0] => HY000 [SQLSTATE] => HY000 [1] => -2146893042 [code] => -2146893042 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot generate SSPI context [message] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot generate SSPI context ) )
Here’s my code. I googled everything. couldn’t find any solution.
<?php
/* $serverName = "PANDORAS-BOXEXP_2008R2"; //serverNameinstanceName, portNumber (default is 1433) */
$serverName = "Server, port"; //serverNameinstanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"XXX", "UID"=>"XX", "PWD"=>"XX","Trusted Connection"=>"yes");
$connectionInfo = [
'CharacterSet' => 'UTF-8',
];
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == True) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "Select Account_Id,Account_No From Savings_Account Where IPKS Is Null";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $conn, $sql , $params, $options );
while( $row = sqlsrv_fetch_array( $stmt) ) {
print json_encode($row);
}
sqlsrv_close($conn);
?>
Captain Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.