I am attempting to connect to an already established database here at work. We don't have access to the back-end, but we do have the server address and the login information to connect to it - I was able to connect last year using PDO and dblib, but dblib is no longer supported in PHP 7 so I am attempting to use the sql server driver.
I set up a basic connection string to test it and am not getting any specified errors, nor am I getting any results:
<?php
//Display All Errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo "Test1";
//Try the Connection
try {
//Connection Variables
$server = "11.123.123.123, 1234";
$database = 'myDatabase';
$username = "myUsername";
$password = "myPassword";
//Connection String
$conn = new PDO ("sqlsrv:Server=$server;Database=$database","$username","$password");
//Initiating Error Detection
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
//Catch exceptions to the Try
catch(Exception $e) {
echo "Test3";
die( print_r( $e->getMessage() ) );
}
//Prepare SQL Statement
$stmt = $conn->prepare("SELECT * FROM WorksheetPriceChangeData");
//Execute SQL Statement
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
echo "Test4";
?>
(placeholders used for sensitive information). This code results in an empty page that displays the "Test1" echo at the top. There are no errors in my PHO log, phpinfo() shows that sqlsrv PDO and the sqlsrv extension (4.0.8629.3) are active, and if I use a bogus server address (like 11.123.123.123) it does the same thing.
I'll also add that I am on Windows Server 2012 R2 and the database is displayed in the Data Source Administrator. It connects successfully with the "With Windows NT authentication using the network login ID" checked and "Connect to SQL Server to obtain default settings for the additional configuration options" checked.
I would appreciate any direction or thoughts offered on this. It's difficult to proceed without even an error message or log.
Kind Regards, Ben David