php remote mssql connection

I have created a php website which is linked to two mssql databases,
i want to keep one of these databases on my local server and put the other onto the webserver

The code below will work fine for the database on the webserver, but what changes do i have to make to this to be able to access the database that is on my local server?

also, is there any changes (security etc) i have to make on my network or to sql server to allow the website to gain access to it?

I'm only a beginner in php so please explain

thanks
<?
$myServer = "server";
$myUser = "user";
$myPass = "pass";
$myDB = "websitedatabase";

$dbhandle = mssql_connect($myServer, $myUser,$myPass) or die("Could not connect to server");
$selected = mssql_select_db($myDB, $dbhandle) or die("Could not open Database");
?>

Open in new window

CoreSupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
>>$myServer = "server";
assuming it has the same username/password are correct:
$myServer = "localhost";
0
CoreSupportAuthor Commented:
sorry i must of confused you somewhere,

the website will be on a webserver along with one database, so i could use localhost to connect to that database, but how to i get connected to the other database which is on a different server than the website?

do i need to use the ip address or port that my server is using?
0
blue-devCommented:
You just need to use the domain like you do now.
If you use localhost, it works because windows / linux maps the domain localhost to represent your local machine. If you want to access your server from outside that machine, you need to use the domain.

Example:
$myServer = "www.myserver.com";

This will do the trick. You do not require a port unless mssql is on a different port then usual. Also be sure to check out if the server is allowed to except connections form non-local-scripts. That may be a future issue cause it would simply block your connection then.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

hieloCommented:
>>do i need to use the ip address or port that my server is using?
Yes, AND that remote site must also accept incoming connections from outside. IF your site is hosted with a web-host, find out if they allow incoming db connections from outside. Some of them do not allow this.
0
CoreSupportAuthor Commented:
thanks hielo, i will check that with them,

so is this how i should structure the db connection:

<?
$myServer = "ipaddress\sqlservername";
$myport = "portnumber";
$myUser = "user";
$myPass = "pass";
$myDB = "websitedatabase";
 
$dbhandle = mssql_connect($myServer, $myport, $myUser,$myPass) or die("Could not connect to server");
$selected = mssql_select_db($myDB, $dbhandle) or die("Could not open Database");
?>

or how do i add the ip address and port into the connection?

thanks again
0
hieloCommented:
if the server is running on the default port, you don't need to provide the part number.
Ex 1 documents how to connect depending on your port:
http://us3.php.net/manual/en/function.mssql-connect.php

<?
$myport = "portnumber";
$myServer = "ipaddress,$myport\sqlservername";

$myUser = "user";
$myPass = "pass";
$myDB = "websitedatabase";
 
$dbhandle = mssql_connect($myServer,$myUser,$myPass) or die("Could not connect to server");
$selected = mssql_select_db($myDB, $dbhandle) or die("Could not open Database");
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.