I had a weird issue with PEAR DB and the hang up was it's call to mssql_select_db. The numbskull who set up the database I was working on called it 'primary'...not a good idea from an SQL perspective since it's part of the SQL syntax (primary key). Trying to select primary as the DB resulted in an error returned as "No database selected" but the native error was "Incorrect syntax near the keyword 'primary'" which tipped me off.
Enclosing the database name in square brackets ([primary]) fixed the issue. Spent a few hours figuring this one out...hope it helps someone else.