To connect to the DDEV database from within PHPStorm, the first step is to define the database container port. This is needed to ensure the connection credentials don't change between restarts of DDEV.