Refactor code that makes mysql and mysql dump calls

#562 added logic for supporting custom ports for `mysql` calls.
#684 added logic for supporting custom ports for `mysqldump` calls.

The logic is the same in both cases: convert `DB_*` constants to CLI parameters.

We can avoid that duplication. Also:

* [ ] pass associative arrays, instead of strings
* [ ] use $env paramter of `proc_open()`, instead of putenv()