nicktherockstar Posted November 11, 2008 Share Posted November 11, 2008 Hi all, I have been searching the net all week for an answer to this one but still nothing.... in short... I have a script which runs connecting up to a bunch of remote (mssql) databases and pulls back a query from them. I am sorry to say however that it will only connect to db's with no spaces in the name. for instance.. datalogger001 - connects ok datalogger 002 - gives error (cannot connect to datalogger) it only seems to use the name up to the first space. With the situation I am in I cannot change the DB names as it is all to do with older and never versions and how they were built at the time, too much uses the db name so they just cannot be changed. Any help on this would make me a very happy man Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/ Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 Show us the code used to connect to database please. Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/#findComment-687675 Share on other sites More sharing options...
nicktherockstar Posted November 11, 2008 Author Share Posted November 11, 2008 yea sorry, it was on another pc so had to mem stick it to get it on here... //connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); the vars are passed into the function but I have tried it plain text in their place. Imagen $myDB is "datalogger001" it will connect if its "datalogger 001" it will not. When it reports back the DB name it only returns it up to the space which is very odd. ??? addition: this is the error( Could not locate entry in sysdatabases for database 'datalogger') the name it attempted to use however as 'datalogger master' Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/#findComment-687685 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 The database name. 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). mssql_select_db('['.$databaseName.']', $connection); Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/#findComment-687696 Share on other sites More sharing options...
nicktherockstar Posted November 11, 2008 Author Share Posted November 11, 2008 Thanks so much funny enough after spending all week I had also just managed to find that answer. with luck this thread will help others suffering witht he same issue Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/#findComment-687701 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 AFAIK this is similar to how it works in MS Access. If you want non standard names, use []. I'd strongly advise anyone to use standard names though (standard, as formed with letters of English alphabet, underscores and digits, and not being reserved words) Link to comment https://forums.phpfreaks.com/topic/132275-solved-spaces-in-database-names-in-this-case-mssql-not-connecting/#findComment-687704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.