Although you’ve already check the list of loaded php modules, the error messages indicates that the php cli configuration seems not be configured correctly. You can e.g. test the database access using the following php test script:
<?php
#$dsn = 'mysql:dbname=nextcloud;unix_socket=/run/mysql/102/mysql.sock';
$dsn = 'mysql:dbname=nextcloud;host=localhost:3306';
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$user = '<user>';
$pass = '<pass>';
try {
$pdo = new PDO($dsn, $user, $pass, $opt);
$sql = "SHOW TABLES";
$stmt = $pdo->query($sql);
print("-start-------------<br>\n");
while ($row = $stmt->fetch())
{
$str = implode($row);
print($str."<br>\n");
}
print("-end---------------<br>\n");
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage() . "\n";
}
?>