Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (localhost)

I installed PHP on IIS. After configured I manage to connect to the MSSQL DB but there is a warning message. I have no idea what it means
(Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (localhost) in C:\Inetpub\wwwroot\global.php on line 39).
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

are you sure your SQL server is running and give correct username/password to the function?
You've entered your username, password or hostname incorrectly. Check your details and try again. You might also need to connect to a specific port.
can you post your code?

other wise we are guessing.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

risk-xAuthor Commented:
This is my code. Thx


//$webhost = '';
//$internalhost = '';
$dbhost ='(localhost)';
$dbuser = 'sa';
$dbpasswd = 'sasa';
$dbname   = 'companylog';

if(!($s = mssql_connect($dbhost, $dbuser, $dbpasswd))) ;

if(!mssql_select_db($dbname)) ;

function mssql_setup() {
      global $dbhost;
      global $dbname;
      global $dbuser;
      global $dbpasswd;

remove the brackets

$dbhost = 'localhost'
risk-xAuthor Commented:
after removed the brackets $dbhost = 'localhost' still the same warning message coming out.
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in C:\Inetpub\wwwroot\global.php on line 30
I think is the setting I missed up. I tried in the ODBC but it show connection successfully connected to local DB. The same script I get from the server to my local computer but there is no such message coming out in the server.
is the mssql server running on the same server where this php file is being served?
risk-xAuthor Commented:
Yes  the mssql server running on the same server where the PHP file is being served. The PHP file is able coonect to the local DB. I just dont know why this message show out as the PHP file is connected with the local DB. There is no problem connect to the local DB, all the data from the DB able to pull out when served the php file. But there is a message showing out on the PHP file ."Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost"
if you don't have problem reading data from the server and don't wanna see tihs message, you can put an @ before the function like this:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
try using the actual IP address,

the MS SQL server may not accept localhost
risk-xAuthor Commented:
Thx a lot after i put @mssql_connect(... there is no warning message coming out alrdy. thx alot.

I got the newest version of ntwdblib.DLL and i got a new message:

Error: [2] mssql_connect() [function.mssql-connect]: message: Login failed for user ''. The user is not associated with a trusted SQL Server connection. (severity 14)Error: [2] mssql_connect() [function.mssql-connect]: Unable to connect to server:
function customError($errno, $errstr)
	echo "<b>Error:</b> [$errno] $errstr";
mssql_connect("xx.xx.xx.xx", "sa", "password");

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.