MsSQL connect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

MsSQL connect

Post by user___ »

Hi guys,
I have a remote MsSQL server and my php is properly configured to use MsSQL ext but I can not connect to that server. This is my code:

Code: Select all

$myServer = "***.***.***.***, 1433";//I have also tried the same server without port
$myUser = "user";
$myPass = "pass";


//Connect
$s = mssql_connect($myServer, $myUser, $myPass) or die("Unable to connect to server: $myServer");
and I get:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: ***.***.***.***, 1433 in C:\www\mssql.php on line 10
Unable to connect to server: ***.***.***.***, 1433
.


Do you have any ideas why I get that warning and I can not connect to the server.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

try with navicat

Post by yacahuma »

download navicat and try to connect to your mysql server from there. If you can , then you should have no problems.

I just mention this to make sure that you have the right permissions to connect remotely
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

yacahuma, he asks about MSSQL, navicat does not support it.

It looks like the MSSql server is down or you use wrong user/pass.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Guys, thank you for your replies. I am not sure whether the server is down because a friend of mine connects through MsSQL server running on his machine but if I try to do the same by using Php it is impossible for a connection to be initiated. I use the credentials that my friend uses for his server but I can not connect by using Php.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you connect to it through Enterprise Manager or some other client interface? Does your server have the necessary drivers to connect to MsSql database servers? Can you ping the IP address of the DB server?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Change your connection call to

Code: Select all

$s = mssql_connect($myServer, $myUser, $myPass) or die("Unable to connect to server: ". mysqli_connect_errno());
That should give you a bit more information
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Or perhaps Jcart meant:

Code: Select all

<?php
$s = mssql_connect($myServer, $myUser, $myPass) or die("Unable to connect to server: ". mssql_get_last_message());
?>
As mysqli functions would probably not give you what you want. ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Whoops, thanks Everah :oops:
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Thank you guys, but I still can not connect to the server but by creating a simple ODBC connection I connect successfully so I suppose that there is nothing wrong with the server.

Do you have any suggestions?

BTW:I got the same output when I updated my query as you suggested.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try setting up a DSN. I think I did that once to connect to a SQL Server database.
Post Reply