#!/bin/bash
:<<'PHP'
<?php

$root = trim(shell_exec('git rev-parse --show-toplevel'));

require $root.'/www/app/config/database.cfg.d/connections.cfg.d/basic.cfg.php';

echo implode(' ', [
    '-h', $config['host'],
    '-u', $config['user'],
    '-p'.$config['password'],
    $config['db'],
]);

__halt_compiler();
PHP

read -ra cmd < <(php "$0" |tail -n1)

run="${1:-mysql}"
shift

exec $run "${cmd[@]}" "$@"
