RE: [PHP] PHP Runs But Does NOT Connect to MSSQL Server
| From: | Boyd, Todd M. | Date: | Fri, 13 Jun 2008 15:41:54 +0000 |
| Subject: | RE: [PHP] PHP Runs But Does NOT Connect to MSSQL Server | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275346@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Wei, Alice J. [mailto:ajwei@indiana.edu]
> Sent: Friday, June 13, 2008 10:25 AM
> To: Greg Maruszeczka; php-general@lists.php.net
> Subject: RE: [PHP] PHP Runs But Does NOT Connect to MSSQL Server
>
> Hi, Greg:
>
> i have went back to the conf file I have in the freetds directory to
> edit the server information to
>
> # A typical Microsoft server
> [egServer70]
> host = 192.168.10.128
> port = 1433
> tds version = 7.2
>
> Since I am using MS SQL 2005, I thought I would have to change this to
> tds version 7.2 instead of 7.0.
> I have edited the MSSQL connection to as follows:
>
> //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");
>
> Since I could not find the exact syntax for this on
http://www.php.net,
> I have modified it as you suggested. The error message that says
> couldn't connect to the server was brought back a lot quicker than
> before, but I still could not connect it.
>
> Are there other packages I have to install?
> Thanks for your help.
>
> Alice
---8<--- snip
> From: Greg Maruszeczka [listmail@websage.ca]
> Perhaps. Check the documentation for myssql_connect and be sure that
> you're not supposed to also provide a port number (in your case 1433)
> along with the hostname argument. IIRC you can tag it after the
> hostname/ip using a colon (e.g. myhostname:1433).
>
> Other than that it seems more like a network connectivity issue. This
> is OT for this list but if it was my problem I'd ensure there aren't
> any packet filters between my web server and db hosts. Since MSSql has
> to run on windows I'd start there and ensure inbound connects to TCP
> 1433 are allowed. You're using private address space (192.168.x.x).
Are
> BOTH servers on the same subnet?
Alice,
You still have not tried to connect to your MS SQL server using your
supplied port number in your code above. A quick glance at
http://us.php.net/mssql_connect shows that a port
number can, in fact,
be passed in the "hostname" parameter. For instance:
$dbhandle = mssql_connect($myServer . "," . $myPort, $myUser, $myPass)
or die("Uh-oh!");
The hostname and port are separated by a comma, as mentioned in the PHP
reference page I have linked to. Give it a shot, and see if it helps at
all.
If not, sorry... but it was worth a try, eh? ;)
Todd Boyd
Web Programmer