Skip to content

Instantly share code, notes, and snippets.



Last active Oct 1, 2019
What would you like to do?
Convert MySQL connection string to wp-config.php parameters
// This will usually be received from an env variable, for example $connectionString = getenv('DB_URL');
$connectionString = 'mysql://';
// The values below will be your default values if $connectionString is empty.
$dbConfig = array_merge(
'host' => 'localhost',
'port' => 3306,
'user' => 'root',
'pass' => '',
'path' => 'wp', // DB_NAME
/** The name of the database for WordPress */
define('DB_NAME', ltrim($dbConfig['path'], '/'));
/** MySQL database username */
define('DB_USER', $dbConfig['user']);
/** MySQL database username */
define('DB_PASSWORD', $dbConfig['pass']);
/** MySQL hostname */
define('DB_HOST', "{$dbConfig['host']}:{$dbConfig['port']}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.