1

I am getting "Fatal error: Invalid handle returned. in" in PHP 7 while trying to connect with SQL Server.

I have already tried below option

Error connecting to MSSQL with SQLSrv and PHP 5.4.7 Unable to connect to SQL Server with PHP

I am using below code:

try {  
   $conn = new PDO( "sqlsrv:Server=(10.10.10.222\sql2008r2);Database=test",'sa', 'sipl@123');   
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
}  

catch( PDOException $e ) {  
   die( "Error connecting to SQL Server" );   
}  

echo "Connected to SQL Server\n";  

$query = 'SELECT *FROM atlas_positions';   
$stmt = $conn->query( $query );   
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){   
    echo '<pre>';
    print_r( $row );   
    echo '</pre>';
} 

Your views will be beneficial for me.

Community
  • 1
  • 1
Ravi Shankar
  • 1,559
  • 1
  • 11
  • 15

1 Answers1

3

Try "ConnectionPooling=0" in DSN, it worked for me.

$conn = new PDO( "sqlsrv:Server=(10.10.10.222\sql2008r2);Database=test;ConnectionPooling=0",'sa', 'sipl@123');  

(My answer is based on @maydimanche's answer from here)

Community
  • 1
  • 1
moni_dragu
  • 1,163
  • 9
  • 16