I get ‘Unable to connect to database’ error when I try to add CometChat on my site.

If you get ‘Unable to connect to database’ error, refer to the solutions listed below:

1. Re-download CometChat

The most common cause of this issue is an incorrectly downloaded integration file. If you are integrating CometChat with WordPress and you select BuddyPress from the drop-down menu before download, the installation will not work correctly.

2. Incorrect Folder

The CometChat folder must be uploaded to the correct directory. Please make sure you upload it to the software root folder.

3. Custom Site

If you are integrating CometChat with a custom site, you will have to manually edit integration.php and add the database details. Do not make this modification if you are using any ready-to-use integration like WordPress, vBulletin etc.

4. Incorrect/empty socket

The default value for mysqli socket is ini_get(“mysqli.default_socket”). It seems that you are using some different socket than the socket defined in php.ini file or you have kept this setting empty.

In cometchat_init.php and /admin/index.php file, replace:

$dbh = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME,$port);

with

$dbh = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME,$port,'/tmp/mysql5.sock');

Not finding what you need?

The CometChat team is here to help!