Bankzilla
Bankzilla

Reputation: 2096

Rest API database connection issues with Codeigniter

I'm using Phil Sturgeons Rest as an API between the server and mobile APP. Locally this works brilliantly, on the server it bounces back with an issue when using API Keys authentication:

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

This is while $config['rest_enable_keys'] = TRUE; is enabled, when I change the variable to false the API service works just fine. Both locally and the server are running the same table layout and both have the same API key in the keys table. Rest of the site works fine doesn't show any database connection errors.

Changing the line $config['rest_database_group'] = 'default'; prompts a different error, which would lead me to believe that it is infact connecting to the correct database, just can't establish the keys table?

You have specified an invalid database connection group.

There's no difference in the code between the server and locally yet locally I get the correct error message of {"status":false,"error":"Invalid API Key."}

Could this be an issue with using multiple database connections? I checked the environment and it seems to be correct but this wouldn't explain why it would work locally.

Upvotes: 0

Views: 1799

Answers (1)

Bankzilla
Bankzilla

Reputation: 2096

Thanks a lot to nithin-meppurathu who helped me debug the core of the rest library to find the problem.

The problem lied in the multiple database connections, due to switching what is used depending on the environment it was always being defaulting back to the 'default' database environment. Changing $config['rest_database_group'] = 'default'; to my ENVIRONMENT variable I was able to get it pointing to the correct place.

Upvotes: 1

Related Questions