Here's the code that I am using.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$myServer = "ip-address:1334/SQLEXPRESS";
$myUser = "username";
$myPass = "password";
$myDB = "dbname";
$link = mssql_connect($myServer, $myUser, $myPass);
if ( !$link ) {
if ( function_exists('error_get_last') ) {
var_dump(error_get_last());
}
die('connection failed');
}
?>
Now this code is running on a linux machine and the server is on a windows server. The IP is correct as well as username, password I created a new pair inside SQLEXPRESS. However, I still get a connection issue.
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server
the port 1334 is opened by our windows server and SQL server is listening to both 1334开发者_如何学C and 1433. THey wont open default port for security reasons. They have double checked the settings but I still cannot connect.
What should be the next action for me.
Kind regards
Khuram
May be the windows SQL server have a firewall restriction which is restricting to access from outside of the server.
For connecting Linux + Apache + SQLEXPRESS 2005 take care about it:
Don´t use the standard MS-SQL port (1433), use the MS-SQL dynamic port under SQL Server Configuration Manager -> SQL Express Protocols -> TCP/IP properties -> IP Adresses -> IPAll
You can do a direct connection (without FreeTDS) using the following statemt:
$db=mssql_connect('192.168.xxx.xxx:1541','usrxxxx','pwdxxxx');
-You can use FreeTDS configuring the freetds.conf file as follow:
[connect2k5]
host = 192.168.xxx.xxx
port = 1541
tds version = 8.0
With the following PHP statement:
$db=mssql_connect('connect2k5','usrxxxx','pwdxxxx');
I have got it from http://php.net/manual/en/function.mssql-connect.php
You can also try http://www.akamarketing.com/blog/99-php-sql-server-connection-problems-mssql_connect-functionmssql-connect-unable-to-connect-to-server.html
The port may not be open. You should be able to connect via telnet to port 1334 or 1433. You won't get any text back, but it will connect.
精彩评论