No API, No Problem: A recipe for connecting to external databases

Apr 02, 2020

In Drupal, there are multiple ways to access external data sources. With the addition of Guzzle in Drupal 8, interacting with REST APIs is easier than ever. There are times though when APIs simply don’t exist for a number of reasons: the requirement has never existed, the budget is too lean, or the team doesn’t have the technical experience to create one. There are some good non-automated solutions like Migrate, Feeds and Entity Importer for doing one-time imports. One option for when an API doesn’t exist is to connect directly to a non-Drupal database to fetch data.

This is not a full demonstration but will show, using code snippets, how to connect to a non-Drupal database and one way to access and use that data.

This session will cover:

Setting up Drupal to work with multiple databases

Connecting to and querying them in custom code

Utilizing a service for code reusability

Using CRON to automate fetching data and updating nodes.

Hi! I'm Karim Boudjema, the developer and site-builder of this site.

I was wondering how could I giving back to the Drupal community all what it gave to me during the last 10 years, that's how the idea of this site came to me ... (read more)

Hi! I’m Santiago Rico, the web designer and themer of this site.

When Karim proposed me to design and theme this site for the Drupal community, I accepted immediately because the community is the main reason why I love Drupal so much.