Skip to main content
Stanford Stanford WebCamp All Things Web - Spring 2021

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

Dev / DevOps

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.