note 39126 deleted from function.mssql-connect by danbrown
| From: | danbrown@php.net | Date: | Sun, 07 Dec 2008 19:48:41 +0000 |
| Subject: | note 39126 deleted from function.mssql-connect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147880@lists.php.net to get a copy of this message | ||
Note Submitter: labrat457_minusthispart!_*-*_!yahoo.com
----
If you aren't "married" to a linux distribution yet, and want a quick turn-key
solution for connecting to a mssql server from apache/php running on linux...here's what worked
for me. Gentoo Linux has the freetds package (and sqsh, which is a cool tool) available as an
emerge-able package (currently v0.61). Install the latest Gentoo distro (at this time is 1.4).
Emerge freetds (and sqsh if you want it). No special make flags were needed. Download the latest
tarballs of apache and php...follow the instructions for building statically. Make sure you include
the "--with-mssql" statement in php ./configure options. With Gentoo, I didn't have
to point the --with-mssql at a particular directory (I simply put "--with-mssql" and
that's it) since freetds was installed via portage and was located automagically. Freetds
looks for a freetds.conf file in several places..one of them being /etc, which was where portage
installed it. My freetds.conf (minus comments and such) looks as follows:
[global]
tds version = 4.2
initial block size = 512
swap broken dates = no
swap broken money = no
try server login = yes
try domain login = no
cross domain login = no
text size = 64512
[MyServer70]
host = 192.168.0.25
port = 1433
tds version = 7.0
This may not be the most optimized config, but it worked. After everything is compiled and
installed (with 4.3.4 I *did not* have to put in a line such as extension=mssql.so as earlier posts
have mentioned in my php.ini file), start apache and try out your install with the following code
snippet:
<?
$msconnect=mssql_connect("MyServer70","sa","");
$msdb=mssql_select_db("Northwind",$msconnect);
$msquery = "select titleofcourtesy,firstname,lastname from employees";
$msresults= mssql_query($msquery);
while ($row = mssql_fetch_array($msresults)) {
echo "<li>" . $row['titleofcourtesy'] . " " .
$row['firstname'] . " " . $row['lastname'] .
"</li>\n";
}
?>
Note, as previously mentioned, the "server" portion of the mssql_connect() must match the
string used in the freetds.conf file. My test mssql server was configured for "mixed mode
authentication", "sa" for admin name, and blank password. Adjust your connection
string for your environment.
It may be just as easy to get this running with RedHat or other distro...your mileage may vary.
This, as I said, was what worked for me and it was very straightforward and worked without any
special tricks. Sorry if this has some redundant info in it, but I hope this helps someone :)
Cheers!