Jump to content

Recommended Posts

please help me I'm desperate!!

 

I have installed PHP version 5.2 - fine

I have SQL Server 2008 - fine

 

Operating system is Windows Server 2008

 

I ran PHP Info and it shows SQL Server loaded as an extension - fine

 

correct DLL's installed including the one that needs to be placed in the windows folder.

 

I am connecting from a standard database connection script (see below) and it keeps coming back as Couldn't connect to server

 

it pauses for a few moments as if it were trying to connect and then spits back the message. If I keep trying it will actually lock the user account in SQL Server and I will have to log in to SQL Server unlock it.

 

This seems as if it is trying to connect but the password is wrong but this cant be..... AND if I log in with the same user name and password into SQL Server that I use in my database connection script, it logs in fine.

 

What have I missed? it doesn't make sense why it wont connect!!!

 

The connection script:

 

$dbhost = 'localhost';

$dbusername = 'theusername';

$dbpasswd = 'thepassword';

$database_name = 'mydatabasename';

 

$connection = mssql_pconnect("$dbhost","$dbusername","$dbpasswd" )

or die ("Couldn't connect to server.");

 

$db = mssql_select_db("$database_name", $connection)

or die("Couldn't select database.");

 

Link to comment
https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/
Share on other sites

There could be any number of reasons but try this one first:

 

Go into sql server and query select @@servername (<instance name>) and put this value instead of localhost.

remove the username and password so you log in as windows authentcation that is if sql server and php are running on the same box.

 

 

$connection = mssql_pconnect('<instance name>','','')

 

Something I just noticed, don't know if you did a typo in your post or it's in your code but:

 

$connection = mssql_pconnect("$dbhost","$dbusername","$dbpasswd" )

 

should be mssql_connect not mssql_pconnect

 

Unless, of course, the OP actually intended to use mssql_pconnect for a persistent connection.

If it's not too late, since you are running on Windows, you should use the Microsoft-supported sqlsrv extension. More detail here: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx

 

Hope that helps.

 

-Brian

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.