What if....
[code]
exec("mysqldump -d -u my_user -pmy_pass my_invalid_database > dump.sql 2>&1", $output_array, $error_level);
[/code]

It doesnt get the error, or I'm wrong at some point?