Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSSQL connect string issue 1

Status
Not open for further replies.

irbk

MIS
Oct 20, 2004
578
US
I have a database name that has a space in it. When I run
Code:
mssql_connect(server, user, password)
It connects to the server, however, when I run
Code:
mssql_select_db(data base)
I get an error that says "Could not locate entry in sysdatabases for database 'data'." Followed by "Unable to select database: data base" Now, since I know that the name of the database is "data base" (with the space) the first error seems to tell me that something about the space is causing issue with the mssql_select_db call. Is there some kind of place holder that I can use to connect to "data base" (like using "data%base" but % doesn't work either).

Thanks in advance.
 
The only thing I can think of off-hand is "\ " (backslash space).

The real fix is to rename the database, replacing the space with an underscore character ("_").



Want the best answers? Ask the best questions! TANSTAAFL!
 
cLFLaVA
1. Technically it's already quoted. I was trying to simplify the code. The entire connection string is
Code:
define ('DB_SERVER', '<server>');
define ('DB_USER', '<user>');
define ('DB_PASSWORD', '<password>');
define ('DB_NAME', '<data base>');
$dbc = mssql_connect (DB_SERVER, DB_USER, DB_PASSWORD)
	or die ('Could not connect to MSSQL');
mssql_select_db (DB_NAME)
	or die ('Could not select the database')
2. Yep, I know better then to use spaces. Unfortunatly, I wasn't the one that created the database and when the person that did create the database learns they are going to have to redo their database so the connection works, there going to learn that lesson too.

sleipnir214
Good guess but no joy :(

Keep the tips coming!
 
Of course, had any of use actually looked in the PHP online manual entry for mssql_select_db() (link), we would have seen the text:

To escape the name of a database that contains spaces, hyphens ("-"), or any other exceptional characters, the database name must be enclosed in brackets, as is shown in the example, below. This technique must also be applied when selecting a database name that is also a reserved word (such as "primary").



Want the best answers? Ask the best questions! TANSTAAFL!
 
CLFlaVA:
Yep.

Or course, I was operating under the assumption that irbk had already looked in the manual and not found what he was looking for.



Want the best answers? Ask the best questions! TANSTAAFL!
 
DOH! Why is it that I always seem to miss the simple answers when they are RIGHT IN THE MANUAL. A serious case of RTFM. I'm no better then a user! E
Thanks a TON to both of you for the posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top