Fix some bugs in database installer

mysql_real_escape_string uses the db resource most recently returned
from mysql_connect (?!) and if we fail to connect, that's an invalid
resource. Wait to call it until after we've connected using the user's
supplied admin credentials.

Also there needed to be some more quoting around $edb when used as a
username or password.