rarex Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
knappy Posted May 15, 2011 Share Posted May 15, 2011 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>','','') Link to comment https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/#findComment-1215631 Share on other sites More sharing options...
knappy Posted May 15, 2011 Share Posted May 15, 2011 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 Link to comment https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/#findComment-1215644 Share on other sites More sharing options...
Pikachu2000 Posted May 15, 2011 Share Posted May 15, 2011 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. Link to comment https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/#findComment-1215692 Share on other sites More sharing options...
Brian Swan Posted May 16, 2011 Share Posted May 16, 2011 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 Link to comment https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/#findComment-1216155 Share on other sites More sharing options...
Muddy_Funster Posted May 30, 2011 Share Posted May 30, 2011 Including some better error capture would help find out what the actual problem is : or die ("Couldn't connect to server. The following error occured :<br><br>".mssql_error()); Link to comment https://forums.phpfreaks.com/topic/236385-cannot-connect-to-database/#findComment-1222221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.