Module Development

Only One Database Connection with a Property for Drupal 8, 9

Sprout Video

Our database is working well, but we currently have things set up so we are duplicating the database information, and that is going to be a nightmare to maintain. In this tutorial, we're going to clean up our database code by isolating the PDO creation in the ShipLoader class. Even with that in place though, we also need to make sure we only return one PDO object. We don't need a new database connection every time it gets called on a page. We'll fix that with a little bit of logic in our PDO code.