I'm not sure about the security risk of having the database connection stuff in the auto_prepend file, but it certainly seems like an unnecessary overhead for scripts that do not need it. Under the theory of layered defenses, anything you can do to potentially make a hacker's job more complicated is good; so if it only takes a small effort to remove that code from the auto_prepend file and put it just where it is needed, I would do so.
Using htmlspecialchars as a database escape function only sort of makes sense for actual HTML strings being saved in the database. It is really more applicable when outputting the data to the browser. While I do not think quotes would be a problem with that, quotes are not the only thing dealt with by functions like mysql_escape_string. If using the Pear MDB2 package, you should probably be using its quote() method for such escaping.