gbvc 发表于 2015-8-27 09:42:42

Cannot connect PHP 5.2.9 to SQL Server 2008

I have a strange problem while connecting to MSSQL 2008 with php.
First I wrote the code myself and I got error message:
Warning: mssql_connect() : Unable to connect to server: 172.16.2.12:1433 in C:\xampp\htdocs\test.php on line 19After googleing for a few hours I found out that with the 2005 version there is some problems with ntwdblib.dll but I cannot find any bugs/problems for this with php 5.2.9 and SQL 2008.
Then I used the code from the Microsoft site:
<?php



// Server in the this format: <computer>\<instance name> or



// <server>,<port> when using a non default port number



$server = '172.16.2.12,1433';







$link = mssql_connect($server, 'Username', 'Password');







if(!$link)



{



die('Something went wrong while connecting to MSSQL');



}



?>But still I get the error:
Warning: mssql_connect() : Unable to connect to server: 172.16.2.12:1433 in C:\xampp\htdocs\test.php on line 19
Yes: The port is 1433;
Yes: The port is open;
Yes: I can connect with telnet;
Yes: The username is correct;
Yes: Also is the password.
Apache server is running local on my workstation.
SQL 2008 is running on remote server (172.17.2.12).
I have no idea what the problem is, and I am sure that the code is correct.
Someone any ideas what this might be?
Thanks in advance;
Lucas Mateijsen

[*]Moved byStoyko Kostov - MSFT Friday, August 07, 2009 4:40 PM (From:SQL Server Data Access)
[*]




[*]Reply
[*]Quote





Answers


[*]

Wednesday, August 12, 2009 3:56 AMNai-dong Jin - MSFTMSFT, Moderator







0Sign In to Vote



Hi,
I think the ntwdblib.dll you used does not support your current SQLServer version.
I suggest that you may try the following link and get the latest ntwdblib.dll and overwrite your original one.
http://www.theregister.co.uk/2008/04/24/database_connection_php/
Thanks.

Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.

[*]Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, August 14, 2009 3:08 AM
[*]




[*]Reply
[*]Quote

[*]

Wednesday, August 12, 2009 5:09 AMjtoddhanard







0Sign In to Vote



  The ntwdblib.dll has never worked for me with any version of sql server other than 7.0.There's so many different versions of the library floating around, its hard to know which one works with which server version.   I think most people who use mssql functions in PHP use the FreeTDS libraries for either Unix or Windows.You can get binaries already made... website is www.freetds.orgI've had success with both 2005 and 2008 sql server.But, since MS wrote a PHP driver, i've had better luck with it.   Both ntwdblib.dll and the freetds libraries use mssql functions but you can only have one running at a time.
Now on a side note, the Microsoft PHP Driver doesn't use the mssql function set, it uses the sqlsrv function set.So, in order to use the MS PHP driver, you need to use sqlsrv_connect, sqlsrv_query, etc.You can run a phpinfo() command in order to determine if you have either of those installed.
This forum is specifically for the microsoft PHP driver, so if you have problems with the ntwdblib, you might want to check some other websites or forums for assistance.
Best of luck


[*]Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, August 14, 2009 3:08 AM
[*]




[*]Reply
[*]Quote




All Replies


[*]

Friday, August 07, 2009 4:41 PMStoyko Kostov - MSFT







0Sign In to Vote



Please don't make duplicate posts.

[*]Unmarked As Answer byLucas Mateijsen Friday, August 07, 2009 7:05 PM
[*]Marked As Answer byLucas Mateijsen Friday, August 07, 2009 7:05 PM
[*]




[*]Reply
[*]Quote

[*]

Wednesday, August 12, 2009 3:56 AMNai-dong Jin - MSFTMSFT, Moderator







0Sign In to Vote



Hi,
I think the ntwdblib.dll you used does not support your current SQLServer version.
I suggest that you may try the following link and get the latest ntwdblib.dll and overwrite your original one.
http://www.theregister.co.uk/2008/04/24/database_connection_php/
Thanks.

Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.

[*]Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, August 14, 2009 3:08 AM
[*]




[*]Reply
[*]Quote

[*]

Wednesday, August 12, 2009 5:09 AMjtoddhanard







0Sign In to Vote



  The ntwdblib.dll has never worked for me with any version of sql server other than 7.0.There's so many different versions of the library floating around, its hard to know which one works with which server version.   I think most people who use mssql functions in PHP use the FreeTDS libraries for either Unix or Windows.You can get binaries already made... website is www.freetds.orgI've had success with both 2005 and 2008 sql server.But, since MS wrote a PHP driver, i've had better luck with it.   Both ntwdblib.dll and the freetds libraries use mssql functions but you can only have one running at a time.
Now on a side note, the Microsoft PHP Driver doesn't use the mssql function set, it uses the sqlsrv function set.So, in order to use the MS PHP driver, you need to use sqlsrv_connect, sqlsrv_query, etc.You can run a phpinfo() command in order to determine if you have either of those installed.
This forum is specifically for the microsoft PHP driver, so if you have problems with the ntwdblib, you might want to check some other websites or forums for assistance.
Best of luck


[*]Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, August 14, 2009 3:08 AM

页: [1]
查看完整版本: Cannot connect PHP 5.2.9 to SQL Server 2008