I'm following these instructions to install the ODBC driver v18 on Ubuntu 22.04. I'm aware that the script does not want to install anything for Ubuntu 22.04 but I bet it's a typo because the repository for 22.04 does exist.
After issuing:
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
it does not find version 18:
$ apt-cache search msodbc
msodbcsql17 - ODBC Driver for Microsoft(R) SQL Server(R)
What is my fault here?
EDIT
Testing code after answer by mizera
:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$SERVER = "192.168.0.50";
$DATABASE = "DB";
$DRIVER = "/usr/lib/libmsodbcsql-18.so";
const USERNAME = "user";
const PASSWORD = "pswd";
try {
$db = new PDO("odbc:driver=$DRIVER;server=$SERVER;database=$DATABASE", USERNAME, PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo '<div class="alert alert-danger" role="alert">';
echo "Connection to database failed:" . PHP_EOL . $e->getMessage();
echo '</div>';
var_dump($e);
}
The output is:
object(PDOException)#3 (8) { ["message":protected]=> string(21) "could not find driver" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(27) "/home/user/www/database.php" ["line":protected]=> int(25) ["trace":"Exception":private]=> array(2) { [0]=> array(5) { ["file"]=> string(27) "/home/user/www/database.php" ["line"]=> int(25) ["function"]=> string(11) "__construct" ["class"]=> string(3) "PDO" ["type"]=> string(2) "->" } [1]=> array(4) { ["file"]=> string(25) "/home/user/www/tables.php" ["line"]=> int(2) ["args"]=> array(1) { [0]=> string(27) "/home/user/www/database.php" } ["function"]=> string(7) "require" } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> NULL }