install/enable sqlsrv/pdo_sqlsrv php8.1 on AlmaLinux v9.4.0
0
votes
1
answer
755
views
The hostgator server updated the linux system from CentOs to Almalinux and now I need to install the sqlsrv drivers again as I only get the error could not find driver
What I've done so far is move these 2 files to the **/opt/cpanel/ea-php81/root/lib64/php/modules** folder on the server
**SQLSRV_8.1_NTS.so**
**PDO_SQLSRV_8.1_NTS.so**
Then I put these 2 lines in php.ini
**extension=SQLSRV_8.1_NTS.so**
**extension=PDO_SQLSRV_8.1_NTS.so**
I restarted the server.
PHPinfo looked like this
The page that connects to the database only displays this message:
**could not find driver**
The PHP code is this:
$drive = 'sqlsrv';
$server = 'host.server.here';
$port = '1443';
$server = $port !== '1443' && is_string($port) ? $server .= ", $port": $server;
$database = 'name_database';
$user = 'user_here';
$pass = 'pass_here';
$pdoConfig = $drive . ":". "Server=" . $server . ";";
$pdoConfig .= "Database=".$database.";";
try {
if(!isset($connection)){
$connection = new PDO($pdoConfig, $user, $pass);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $connection;
}
}catch (PDOException $e) {
print_r($e->getMessage());
return null;
}


Asked by Maico Rossarola
(1 rep)
Jul 24, 2024, 12:05 PM
Last activity: Jul 25, 2024, 11:26 AM
Last activity: Jul 25, 2024, 11:26 AM