PHP Connecting to mssql

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
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

PHP Connecting to mssql

Post by hairytea »

Hi,

I have been unsuccessful at trying to gain access to a remote mssql server (not mysql).....quick question....

Does the remote mssql server need to have php installed or is it just the webserver that is trying to connect to the mssql server that needs php supported?

I have tried script after script from all over the place including php.net codes. I have all the parimeters needed i.e. username password ip address etc and the following code is what i am trying to use at present....

Code: Select all

 
<?php
$myServer = "IP-REMOVED";
$myUser = "USERNAME-REMOVED";
$myPass = "PASSWORD - REMOVED";
$myDB = "DATABASENAME - REMOVED";
 
// connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass) 
    or die("Couldn't connect to SQL Server on $myServer");
 
// select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
 
echo "You are connected to the " . $myDB . " database on the " . $myServer . ".";
 
// close the connection
mssql_close($dbhandle);
?>
 
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Connecting to mssql

Post by highjo »

is your codes given an error or something?What's the deal?
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: PHP Connecting to mssql

Post by hairytea »

Thank you for the speedy response...

I just get my error printed to the screen....

Couldn't connect to SQL Server on IP-REMOVED

Many thanks
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: PHP Connecting to mssql

Post by hairytea »

I need to clarify whether the sql server needs to have php installed or not?

This maybe my problem????

FYI: The webserver has php support but i dont have access to the sql server i am trying to connect to and i really do not know whether that has php installed nor whether it neds php installed?

Is it just the web server that neds php installed?
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Connecting to mssql

Post by highjo »

don't think mssql care about where the client is calling from.it cares whether the client has the drivers(as far as i'm concerned).can you check first if you can connect with mssql client?if it works then we would now worry about the version of php you are using, because i'll suggest to use PDO or PEAR DB package.
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: PHP Connecting to mssql

Post by hairytea »

highjo wrote:don't think mssql care about where the client is calling from.it cares whether the client has the drivers(as far as i'm concerned).can you check first if you can connect with mssql client?if it works then we would now worry about the version of php you are using, because i'll suggest to use PDO or PEAR DB package.
Thank you but could you please clarify...

Do you mean the web server needs to have mssql drivers as well as the remote server i am trying to connect to?

Not sure what PDO or PEAR package is? Could you elaborate?

How do i connect with a mssql client? What is mssql client?

Do you mean a machine on the same network as the server? if yes i am remoting in and the server and it's local clients on network are not accesible for me!
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Connecting to mssql

Post by highjo »

before we go further can you describe your system configuration?i mean by that if you have iis and php as module + mssql or using apache +php
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: PHP Connecting to mssql

Post by hairytea »

highjo wrote:before we go further can you describe your system configuration?i mean by that if you have iis and php as module + mssql or using apache +php

The web server that scripts are uploaded to supports php5 does NOT have mysql or mssql.

(The remote server i am trying to connect to from the web server is the sql server)

From running phpinfo.php i see the server is running iis6 (http://www.icaltd.co.uk/phpinfo.php)

Is this what you needed?
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Connecting to mssql

Post by highjo »

yeah i can see that it's from a hosting company.that means we have limited options.what i meant by mssql client is your microsoft sql server (like 2000 or 2005) installed on your machine where you develop.With that you can try to connect to your remote sql database by creating new connection and enter your credentials.see whether the connection is ok.
then i'm afraid your have to write to your hosting administrator or support service.explain the problem and ask them if the have enabled TCP/IP and Named Pipes Protocol in MS SQL Server.if you want to know about all this check this http://www.php.net/function.mssql-connect and http://www.daniweb.com/forums/thread22564.html
Post Reply