Database access from within the environment

How to configure code to connect to the database on fortrabbit.

# Automatic software configuration

We recommend ENV var configuration. Thanks to software templates ENV vars for connecting to the database are automatically mapped. Software like Laravel, Symfony, Craft CMS or Statamic will connect to the database without additional configuration.

// Generic example for illustration purposes
$pdo = new \PDO(
  'mysql:host='. getenv('MYSQL_HOST'). ';dbname='. getenv('FORTRABBIT_DATABASE'),
  getenv('DATABASE_USER'),
  getenv('DATABASE_PASSWORD'),
);
$pdo->query("SELECT * FROM ...")
php

Environment variables for database connections that are automatically mapped to specific keys for various software systems:

  • FORTRABBIT_DATABASE
  • FORTRABBIT_DATABASE_USER
  • FORTRABBIT_DATABASE_PASSWORD
  • FORTRABBIT_DATABASE_HOST
  • FORTRABBIT_DATABASE_PORT

# Manual software configuration

WordPress, for example, does not support ENV configuration. You will need to enter the database credentials during the install process or with the configuration files. Please look up the database credentials, such as database name, user and password with the dashboard.

Log in to see the link here.

# Connecting via SSH session

The command-line tools mysql and mysqldump are available via SSH. When you are logged just type mysql to login to the MySQL server.

Found a tpyo?Edit