I’m on a shared hosting platform with Krystal running Ubuntu, trying to connect to an SQL database in house with PHP but I’m getting the error:
Caught PDO exception:
SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712
Yet looking at phpinfo – the driver looks like it’s running…
Here’s my code
<?php
try {
$serverName = "server***";
$databaseName = "db***";
$uid = "uid***";
$pwd = "pwd***";
$conn = new PDO("sqlsrv:server = $serverName; Database = $databaseName;", $uid, $pwd);
// Select Query
$tsql = "SELECT @@Version AS SQL_VERSION";
// Executes the query
$stmt = $conn->query($tsql);
} catch (PDOException $exception1) {
echo "<h1>Caught PDO exception:</h1>";
echo $exception1->getMessage() . PHP_EOL;
echo "<h1>PHP Info for troubleshooting</h1>";
phpinfo();
}
?>
<h1> Success Results : </h1>
<?php
try {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['SQL_VERSION'] . PHP_EOL;
}
} catch (PDOException $exception2) {
// Display errors
echo "<h1>Caught PDO exception:</h1>";
echo $exception2->getMessage() . PHP_EOL;
}
unset($stmt);
unset($conn);
?>
I’ve Googled the hell out of this – everything points to the driver missing but looking at phpinfo, if I’m reading it correctly, everything is there – any ideas?
PHP Info