Re: PHP and MSSQL Connection on IIS 5.1
| From: | Elizabeth M Smith | Date: | Tue, 17 Jun 2008 19:58:32 +0000 |
| Subject: | Re: PHP and MSSQL Connection on IIS 5.1 | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-28929@lists.php.net to get a copy of this message | ||
Wei, Alice J. wrote:
> Hi, Guys:
>
> This is my first time running PHP 5.2 on a IIS 5.1 Server using a Windows XP machine.
> My client wants me to build the PHP scripts and the database on one single machine. So far I
> could run the PHP fine, but I am having a hard time connecting to the MSSQL database even though it
> is on one machine.
>
> I have created a freetds.conf file and have it set in the Windows directory in the following
> format:
>
> [global]
> host = 192.168.10.62
> port = 1433
> client charset = UTF-8
> tds version = 8.0
> text size = 20971520
>
> I have then went into C:\Inetpub\wwwroot\test and built a index.php script, with my code as
> follows:
>
> <html>
> <head>
> <title>PHP Test</title>
> </head>
> <body>
> <?php
> echo "<p>Hello!</p>";
> $myServer = "global";
> $myUser = "user";
> $myPass = "password";
> $myDB = "books";
> // 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);
> ?>
> </body>
> </html>
>
> So far I only get this from the screen:
>
> Hello!
> Couldn't connect to SQL Server on global
>
> Is there anything else I have missed? I have followed the prompts of installing FreeTDS
> according to http://docs.moodle.org/en/Installing_MSSQL_for_PHP,
> Would anyone say if I use something like ODBC would work better?
>
> I welcome any suggestions.
>
> Alice
> ======================================================
> Alice Wei
> MIS 2009
> School of Library and Information Science
> Indiana University Bloomington
> ajwei@indiana.edu
I've found that ODBC or PDO_ODBC works much better with Microsoft SQL if
PHP is on windows - the native client driver odbc connection string
works really well with MSSQL 2005 ;) Usually freetds is only needed if
you need to connect from a linux box with PHP to a windows box with mssql.
Thanks,
Elizabeth