Doctrine\DBAL\DBALException failes do connect to the database

Steps to reproduce

  1. Error 404 received when trying to log to owncloud
  2. No occ in /var/www/owncloud/
  3. backups of config/ and data/ folder done.
  4. backup of the database (mysql) done.
  5. force reinstallation of owncloud though sudo apt-get install owncloud-files
  6. config/ & data/ folders copied back
  7. try occ upgrade

Expected behaviour

Owncloud running as it used to do.

Actual behaviour

I receive this error message that I do not understand.
I found other topic with that error but I do not have understood how to fix it yet.

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 /var/www/owncloud/lib/private/DB/Connection.php:63
Stack trace:

0 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()

1 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()

2 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()

3 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()

4 /var/www/owncloud/lib/private/DB/Connection.php(146): Doctrine\DBAL\Connection->setTransactionIsolation(2)

5 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))

6 /var/www/owncloud/lib/private/DB/ConnectionFactory.php(140): Doctrine\DBAL\DriverManager::getConnection(Array, Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))

7 /var/www/owncloud/lib/private/Server.php(472): OC\DB\ConnectionFactory->getConnection('mysql', Array)

8 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC{closure}(Object(OC\Server))

9 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(111): Pimple\Container->offsetGet('DatabaseConnect...')

10 /var/www/owncloud/lib/private/ServerContainer.php(87): OC\AppFramework\Utility\SimpleContainer->query('DatabaseConnect...')

11 /var/www/owncloud/lib/private/Server.php(1121): OC\ServerContainer->query('DatabaseConnect...')

12 /var/www/owncloud/lib/private/Server.php(233): OC\Server->getDatabaseConnection()

13 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC{closure}(Object(OC\Server))

14 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(111): Pimple\Container->offsetGet('AccountMapper')

15 /var/www/owncloud/lib/private/ServerContainer.php(87): OC\AppFramework\Utility\SimpleContainer->query('AccountMapper')

16 /var/www/owncloud/lib/private/Server.php(973): OC\ServerContainer->query('AccountMapper')

17 /var/www/owncloud/lib/private/Server.php(238): OC\Server->getAccountMapper()

18 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC{closure}(Object(OC\Server))

19 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(111): Pimple\Container->offsetGet('UserManager')

20 /var/www/owncloud/lib/private/ServerContainer.php(87): OC\AppFramework\Utility\SimpleContainer->query('UserManager')

21 /var/www/owncloud/lib/private/Server.php(966): OC\ServerContainer->query('UserManager')

22 /var/www/owncloud/lib/private/Server.php(278): OC\Server->getUserManager()

23 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC{closure}(Object(OC\Server))

24 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(111): Pimple\Container->offsetGet('UserSession')

25 /var/www/owncloud/lib/private/ServerContainer.php(87): OC\AppFramework\Utility\SimpleContainer->query('UserSession')

26 /var/www/owncloud/lib/private/Server.php(990): OC\ServerContainer->query('UserSession')

27 /var/www/owncloud/lib/private/Server.php(518): OC\Server->getUserSession()

28 /var/www/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(113): OC\Server->OC{closure}(Object(OC\Server))

29 /var/www/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(111): Pimple\Container->offsetGet('AppManager')

30 /var/www/owncloud/lib/private/ServerContainer.php(87): OC\AppFramework\Utility\SimpleContainer->query('AppManager')

31 /var/www/owncloud/lib/private/Server.php(1311): OC\ServerContainer->query('AppManager')

32 /var/www/owncloud/lib/private/legacy/app.php(313): OC\Server->getAppManager()

33 /var/www/owncloud/lib/private/legacy/app.php(107): OC_App::getEnabledApps()

34 /var/www/owncloud/lib/base.php(579): OC_App::loadApps(Array)

35 /var/www/owncloud/lib/base.php(1013): OC::init()

36 /var/www/owncloud/console.php(64): require_once('/var/www/ownclo...')

37 /var/www/owncloud/occ(11): require_once('/var/www/ownclo...')

38 {main}PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /var/www/owncloud/lib/private/DB/Connection.php:63

Stack trace:

0 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()

1 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()

2 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()

3 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()

4 /var/www/owncloud/lib/private/DB/Connection.php(146): Doctrine\DBAL\Connection->setTransactionIsolation(2)

5 /var/www/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\D in /var/www/owncloud/lib/private/DB/Connection.php on line 63

Server configuration

Operating system: Ubuntu 16.04

Web server: apache2

Database: mysql

PHP version: php7.0

ownCloud version: (see ownCloud admin page)

Updated from an older ownCloud or fresh install: older owncloud

Where did you install ownCloud from: apt-get install owncloud-files

Signing status (ownCloud 9.0 and above): owncloud 10.0

Login as admin user into your ownCloud and access 
http://example.com/index.php/settings/integrity/failed 
paste the results into https://gist.github.com/ and puth the link here.

The content of config/config.php:

Log in to the web-UI with an administrator account and click on
'admin' -> 'Generate Config Report' -> 'Download ownCloud config report'
This report includes the config.php settings, the list of activated apps
and other details in a well sanitized form.

or 

If you have access to your command line run e.g.:
sudo -u www-data php occ config:list system
from within your ownCloud installation folder

*ATTENTION:* Do not post your config.php file in public as is. Please use one of the above
methods whenever possible. Both, the generated reports from the web-ui and from occ config:list
consistently remove sensitive data. You still may want to review the report before sending.
If done manually then it is critical for your own privacy to dilligently
remove *all* host names, passwords, usernames, salts and other credentials before posting.
You should assume that attackers find such information and will use them against your systems.

List of activated apps:

If you have access to your command line run e.g.:
sudo -u www-data php occ app:list
from within your ownCloud installation folder.

Are you using external storage, if yes which one: local/smb/sftp/...

Are you using encryption: yes/no

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...

LDAP configuration (delete this part if not used)

With access to your command line run e.g.:
sudo -u www-data php occ ldap:show-config
from within your ownCloud installation folder

Without access to your command line download the data/owncloud.db to your local
computer or access your SQL server remotely and run the select query:
SELECT * FROM `oc_appconfig` WHERE `appid` = 'user_ldap';


Eventually replace sensitive data as the name/IP-address of your LDAP server or groups.

Client configuration

Browser:

Operating system:

Logs

Web server error log

Insert your webserver log here

ownCloud log (data/owncloud.log)

Insert your ownCloud log here

Browser log

Insert your browser log here, this could for example include:

a) The javascript console log
b) The network log 
c) ...

please run php -m and paste the output

Here is the output of php -m:
[PHP Modules]
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

no mysql module -> it cannot connect.

Oh i see...

After a apt-get install php-mysql i have now:
[PHP Modules]
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

Now trying again sudo -u www-data php occ, I receive this message:
Error: Call to undefined function OC\App\simplexml_load_file() in /var/www/owncloud/lib/private/App/InfoParser.php:41
Stack trace:

0 /var/www/owncloud/lib/private/legacy/app.php(683): OC\App\InfoParser->parse('/var/www/ownclo...')

1 /var/www/owncloud/lib/private/AppFramework/App.php(53): OC_App::getAppInfo('files')

2 /var/www/owncloud/lib/private/legacy/app.php(195): OC\AppFramework\App::buildAppNamespace('files')

3 /var/www/owncloud/lib/private/legacy/app.php(113): OC_App::registerAutoloading('files', '/var/www/ownclo...')

4 /var/www/owncloud/lib/base.php(579): OC_App::loadApps(Array)

5 /var/www/owncloud/lib/base.php(1013): OC::init()

6 /var/www/owncloud/console.php(64): require_once('/var/www/ownclo...')

7 /var/www/owncloud/occ(11): require_once('/var/www/ownclo...')

Looks like you're again missing another PHP module/extension. A google search for this could give you some pointers which one you need to install

Please read up our docs where we explain which modules are required. THX

Hi there,
I have the same problem after moving to oc 10.2.0 and changing php to 7.2 on my shared hosting :frowning:

All required modules seem to be loaded

opary@opary:~$ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dbase
dom
exif
fileinfo
filter
ftp
gd
geoip
gettext
hash
iconv
imagick
imap
intl
ionCube Loader
json
ldap
libxml
mailparse
mbstring
memcached
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
pspell
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SourceGuardian
SPL
sqlite3
ssh2
standard
sysvsem
sysvshm
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
SourceGuardian
Zend OPcache
the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured)

opary@opary:~$

But I got this message while trying to occ upgrade.
No idea how to fix it :frowning:

opary@opary:~/owncloud$ php occ upgrade
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connecti on timed out in /home/opary/ftp/owncloud/lib/private/DB/Connection.php:62
Stack trace:
#0 /home/opary/ftp/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /home/opary/ftp/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getData basePlatformVersion()
#2 /home/opary/ftp/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectD atabasePlatform()
#3 /home/opary/ftp/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getData basePlatform()
#4 /home/opary/ftp/owncloud/lib/private/DB/Connection.php(144): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /home/opary/ftp/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct( Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#6 /home/opary/ftp/owncloud/lib/private/DB/ConnectionFactory.php(145): Doctrine\DBAL\DriverManager::getConnection(Array, Object (Doctrine\DBAL\Configuration), Object(Doctrine\Common\EventManager))
#7 /home/opary/ftp/owncloud/lib/private/Server.php(531): OC\DB\ConnectionFactory->getConnection(‘mysql’, Array)
#8 /home/opary/ftp/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC{closure}(Object(OC\Server) )
#9 /home/opary/ftp/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet(‘DatabaseCon nect…’)
#10 /home/opary/ftp/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query(‘DatabaseConne ct…’)
#11 /home/opary/ftp/owncloud/lib/private/Server.php(1216): OC\ServerContainer->query(‘DatabaseConnect…’)
#12 /home/opary/ftp/owncloud/lib/private/Server.php(405): OC\Server->getDatabaseConnection()
#13 /home/opary/ftp/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC{closure}(Object(OC\Server ))
#14 /home/opary/ftp/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet(‘AppConfig’ )
#15 /home/opary/ftp/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query(‘AppConfig’)
#16 /home/opary/ftp/owncloud/lib/private/Server.php(1146): OC\ServerContainer->query(‘AppConfig’)
#17 /home/opary/ftp/owncloud/lib/private/Server.php(586): OC\Server->getAppConfig()
#18 /home/opary/ftp/owncloud/lib/composer/pimple/pimple/src/Pimple/Container.php(118): OC\Server->OC{closure}(Object(OC\Server ))
#19 /home/opary/ftp/owncloud/lib/private/AppFramework/Utility/SimpleContainer.php(108): Pimple\Container->offsetGet(‘AppManager ‘)
#20 /home/opary/ftp/owncloud/lib/private/ServerContainer.php(86): OC\AppFramework\Utility\SimpleContainer->query(‘AppManager’)
#21 /home/opary/ftp/owncloud/lib/private/Server.php(1414): OC\ServerContainer->query(‘AppManager’)
#22 /home/opary/ftp/owncloud/lib/private/legacy/app.php(343): OC\Server->getAppManager()
#23 /home/opary/ftp/owncloud/lib/private/legacy/app.php(107): OC_App::getEnabledApps()
#24 /home/opary/ftp/owncloud/lib/base.php(577): OC_App::loadApps(Array)
#25 /home/opary/ftp/owncloud/lib/base.php(994): OC::init()
#26 /home/opary/ftp/owncloud/console.php(64): require_once(’/home/opary/ftp…’)
#27 /home/opary/ftp/owncloud/occ(11): require_once(’/home/opary/ftp…’)
#28 {main}opary@opary:~/owncloud$

Hey,

looks to me unrelated to the problem discussed initially:

and has probably a completely different reason. Maybe a moderator like @lefherz or @dmitry could split this issue in a new thread?

1 Like

You are right, at first I havent noticed a difference,
SQLSTATE[HY000] [2002] vs could not find driver.
I have just reverted OC to 10.1.0.4 and it works again, but…
When I go to SSH I still encounter the same problem:

opary@opary:~/owncloud$ php occ help
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection timed out in /home/opary/ftp/owncloud/lib/private/DB/Connection.php:62

Hey,

“Connection timed” sounds to me like some sort of problems with the database connection itself or some too low timeout values.

Personally i would re-check my database setup and configuration.

Connection to database works, b/c owncloud itself works (in browser),
I can login in, see user list, transfer files and so on…
I cant manage it through SSH (occ command).

I’m on shared hosting with limited access to SSH (no root),
MariaDB is on different machine and I have only access to my DB with phpmyadmin.

Hey,

from what i have read in the past running ownCloud within a web server is not necessarily the same as running ownCloud / occ via the command line.

For example it might be possible that the hosting system has additional restrictions / limitations for the SSH user in place preventing PHP (and thus the occ command line tool) to access e.g. a network system (your remote MariaDB database) which doesn’t apply for the user running the web server hosting ownCloud.

Hmm,
it seems that you are right. I cant connect to SQL server with mysql command
from shared hosting to their SQL.

opary@opary:~$ mysql -u XXXXXXX -h sql.opary.nazwa.pl -pXXXXXXX

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘sql.opary.nazwa.pl’ (110 “Connection timed out”)

opary@opary:~$

but I can connect with mysql command from my private VPS:

nawrocki@vps:~$ mysql -u XXXXXXXXXX -h sql.opary.nazwa.pl -pXXXXXXX

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 7051679

Server version: 10.1.38-MariaDB mariadb.org binary distribution

Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

Ask your hosting provider if they have an outgoing firewall rule, and if yes if they can create an exception for you.

Edit: not sure if that makes sense, since it works with a previous ownCloud version…

1 Like

I asked them to solve the problem (whatever it is - fw or security policies)
and they did it. It is working now.
But I still dont know where was the problem.

1 Like