1

Using php I am trying to connect to a SQL Server table which has a hyphen in the name, error returned is

Warning: mssql_select_db() [function.mssql-select-db]: message: Could not locate entry in sysdatabases for database 'SMD'. No entry found with that name. Make sure that the name is entered correctly. (severity 16) in C:\xampp\xampp\htdocs\second.php on line 12

Warning: mssql_select_db() [function.mssql-select-db]: Unable to select database: SMD-GROUP in C:\xampp\xampp\htdocs\second.php on line 12
Couldn't open database SMD-GROUP

Code is

    $myDB = "SMD-GROUP"; 
     $selected = mssql_select_db($myDB, $dbhandle)
     or die("Couldn't open database $myDB"); 
3
  • try wrapping them with brackets as "[SMD-GROUP]" Commented Feb 22, 2012 at 10:41
  • PHP's MSSQL-driver is outdated and in fact disconinued for PHP 5.3. You should consider switching to Microsoft's SQL Server Driver for PHP (SQLSRV): msdn.microsoft.com/en-us/sqlserver/ff657782.aspx Commented Feb 22, 2012 at 10:50
  • Try reading the documentation for the function you're using. This is covered there. Commented Feb 22, 2012 at 11:08

3 Answers 3

6

Have a look at http://php.net/manual/en/function.mssql-select-db.php:

To escape the name of a database that contains spaces, hyphens ("-"), or any other exceptional characters, the database name must be enclosed in brackets.

Sign up to request clarification or add additional context in comments.

Comments

1

if you are using MSSQL server 2005 or higher.. you should use SQLSRV drivers by microsoft. Be careful, there are still incompetency on the performance due to unresolve bugs on PHP5.4 and up. You should know if your PHP is compiled on VC6 or VC9 also if it is thread safe or not.. better to see this reference http://php.net/manual/en/book.sqlsrv.php.

remember that php_mssql.dll is already deprecated on PHP5.4 and higher. Also, I already test this on our UAT and Producion servers. Cheers!

Comments

0

It is better if you use PDO class for database connections with PHP, since PDO supports multiple DB drivers and is better supported. PHP Data Objects

$DB=new PDO('dblib:host='.$host.';dbname='.$database,$username,$password);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.