0

I'm trying to connect to a local MSSQL Database via PHP (PDO) using following Code:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$db = new PDO("sqlsrv:Server=10.5.5.1,1433;Database=PWS", "Administrator", "password");

if(!$db)
{
echo mysqli_connect_error();
}
else
{
echo 'connected';
}

?>

I'm getting following error message: Fatal error: Uncaught PDOException: could not find driver in /var/www/html/test/index.php:5 Stack trace: #0 /var/www/html/test/index.php(5): PDO->__construct() #1 {main} thrown in /var/www/html/test/index.php on line 5

PHP is running on an Ubuntu 20.04.4 LTS with following modules installed:

libapache2-mod-php8.0
php-common
php8.0
php8.0-bz2
php8.0-cli
php8.0-common
php8.0-gd
php8.0-interbase
php8.0-mbstring
php8.0-mysql
php8.0-opcache
php8.0-readline
php8.0-xml
php8.0-zip

According to phpinfo();, pdo, pdo_mysql, pdo_firebird are enabled

Oliver
  • 1
  • 1
  • 4
    You're connecting to `sqlsrv` i.e. Microsoft SQL Server, so the pdo_mysql and pdo_firebird packages are not going to help you. You'll want pdo_sqlsrv installed – aland Jul 25 '22 at 07:59
  • `mysqli_connect_error` is also not going to be of any use to you here; even if you were using the MySQL, you can't just mix the mysqli and PDO functions like that. – IMSoP Jul 25 '22 at 08:01

0 Answers0