NC 15 OCC Failed to connect to the database

I have problems to launch several occ commands, like

sudo -u http php70 occ db:add-missing-indices

always get the following Error:

 An unhandled exception has been thrown:
 Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: 
 could not find driver in /volume1/web/nextcloud/lib/private/DB/Connection.php:64

When I use phpinfo() without the VirtualHost I can see that the
mysqli, mysqlnd and pdo_mysql are activated in php 7.0.
But when I use php70 -m on the shell (thats where I execute the occ command) I only get the following list of modules:

[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
json
libxml
mbstring
mysqlnd
pcntl
pcre
PDO
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

I’m running MariaDB 10 on socket 3307.
Beside this, the upgrade from 14.0.4 worked after a few issues, but actually seems to be OK, besode of some missing indexes and a few other things

Nextcloud version : 15.0.0
Operating system and version: DSM 6.2.1-23824 Update 4
Apache or nginx version : 2.4
PHP version : 7.0

I get no entry in the Nextcloud log :

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'xxxxxx',
  'passwordsalt' => 'yyyyyyyy',
  'secret' => 'zzzzzzzzzz',
  'trusted_domains' => 
  array (
    0 => 'data.domain.com',
  ),
  'datadirectory' => '/volume1/web/data_new',
  'overwrite.cli.url' => 'https://data.domain.com/nextcloud',
  'dbtype' => 'mysql',
  'version' => '15.0.0.10',
  'dbname' => 'nextcloud',
  'dbhost' => '127.0.0.1:3307',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_user',
  'dbpassword' => '------',
  'installed' => true,
  'theme' => '',
  'loglevel' => 2,
  'maintenance' => false,
  'updater.secret' => 'xxxxxx',
  'updater.release.channel' => 'stable',
);

After searching, testing and reading it is now getting clearer.
The problem I encountered is NOT an NEXTCLOUD issue, but has to do with the confusing (at least for me) PHP handling my Synology Diskstation does (Nextcloud is running on it).
The PHP-CLI uses a different version php.ini file (located in /urs/local/etc/php70/) than the webstation does (located in /volume1/@appstore/WebStation/misc/). So configuring the PHP version for the Webstation does only affect the php.ini from the WebStation which is used to run Nextcloud in the browser. This means that the webupdater could behave different from the occ-script launched via terminal, even if both run PHP 7.0.
To get things work I first need to unterstand this.

The PHP configuring via the GUI of DS > WebStation only affects the PHP-version that is used by the web updater.
The configuration of the PHP-version used by the CLI, to run occ commands needs to be set in the php.ini in the /urs/local/etc/php70/ folder. Most missing modules can easily be enabled by just adding ‘extension = pdo_mysql.so’, … to the php.ini-file (e.g. using midnight commander as root (sudo -i)).

I hope this might help You, when You encounter errors like the following:

Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /volume1/web/nextcloud/lib/private/DB/Connection.php:64

At least on Synology, which a few of us run Nextcloud on, migth help to unterstand whats wrong, and where / how things could be solved.
Happy New Year and happy nextclouding.

super !

mark your post as fixed please

which PHP directive is exactly?

Thank you for documenting your issue and solution. I’m hoping to solve a similar issue.

The accepted solution to this does not work for me, and this post is the top hit when searching for the same problem with Nextcloud version 24 (and presumably those in between).

In case this is helpful to anyone else, I solved the problem by adding

require_once __DIR__ . '/config/config.php';

to the file “occ” in the Nextcloud system directory, before “require_once DIR . ‘/console.php’;”.

On Synology, it is then necessary to specify a version of php to run, so the command I used was

sudo -u http php74 occ