PDA

View Full Version : how can i build php with MS SQL support



limpangel
09-19-2008, 04:37 AM
is there anything that needs to be done except adding "--with mssql" in configure/configure.php5?
do i have to install a rpm or something?
any pointers will be greatly appreciated :)


Currently running Fedora 4 with:
Apache 2.0.63
PHP 5.2.6
MySQL 5.0.51a
Dovecot 1.1.3

vandal
09-23-2008, 03:59 PM
You may have to install freetds as well. But their website is down :(

limpangel
09-24-2008, 08:25 AM
After days of searching the web i found something related to this and took a leap of faith.
I'll post the steps i followed, maybe it helps someone.

1. Install unixODBC package via yum or the package manager of your OS. It has some libs required by FreeTDS (at least in my case).

2. Download FreeTDS
I used freetds-0.63.tar.gz (reason unknown :confused:) from http://www.ibiblio.org/pub/Linux/ALPHA/freetds/old/0.63/

Latest stable version can be found here http://www.ibiblio.org/pub/Linux/ALPHA/freetds/stable/ (0.82 at the time of this post)
(I also found an rpm but that didn't work for me.)

3. Configure and install FreeTDS
Uncompress and cd to the respective folder:

./configure --with-tdsver=4.2 --prefix=/usr/local/freetds
make
make install

4. PHP configuration
Edit the php configuration file.
"/usr/local/directadmin/custombuild/configure/ap2/configure.php5" in my case. (i use apache 2.0.63 and php 5.2.6)
Add this line: "--with mssql=/usr/local/freetds" (without quotes)

Go to custombuild:
./build clean
./build php n

All done. :)
This worked for me, but I think it will work on any system or configuration.

smtalk
09-30-2008, 06:44 AM
Patch if you want freetds 0.82: http://bugs.php.net/bug.php?id=44991

massive
05-25-2009, 04:04 PM
I tried the solution but it doesn't work.
Any advice?

scsi
05-26-2009, 06:43 AM
Get a windows server if you want mssql.

massive
05-26-2009, 08:31 AM
Why i have to buy a windows server?

nobaloney
05-28-2009, 12:24 PM
Because MSSQL is a Microsoft product. It doesn't work on either Linux or FreeBSD.

Jeff

limpangel
05-29-2009, 12:01 PM
As it was pointed out by Jeff, MSSQL server is a Microsoft product thus only works on Windows.
The guide i posted back in september provides you with the means to connect to a MSSQL server from php on a Fedora core 4 OS which is not supported anymore and yum did not work for me.

In the meantime I installed CentOS 5 and I made it work like this:
1. Install freetds:

yum install freetds

2. Edit the php configuration file (i have apache 2 and php 5, change acording to your configuration):


mkdir /usr/local/directadmin/custombuild/custom/ap2
cp /usr/local/directadmin/custombuild/configure/ap2/configure.php5 /usr/local/directadmin/custombuild/custom/ap2

edit and add this line to /usr/local/directadmin/custombuild/custom/ap2/configure.php5:

--with mssql=/usr \
(Note: if you write this at the end of the file make sure you remove "\" and add it to the line before it)

3. Rebuild php:


cd /usr/local/directadmin/custombuild
./build clean
./build update
./build php n


Again, this does not install MSSQL server on your Linux host (that is only posible with Windows), but merely provides you with the means to connect to an external MSSQL database.
Hope this helps.

nobaloney
05-29-2009, 02:09 PM
Thanks, limpangel. This is one of those cases where responding only to the message rather than reading the thread has made me look a bit of a fool :).

Jeff

massive
05-30-2009, 02:21 PM
Thanks, limpangel. This is one of those cases where responding only to the message rather than reading the thread has made me look a bit of a fool :).

Jeff

I was ready to respond but someone did it before :)

tundasrl
03-20-2010, 02:51 PM
--with-mssql=/usr \(Note: if you write this at the end of the file make sure you remove "\" and add it to the line before it)

3. Rebuild php:


I found a typo but it still doesn't works..

tundasrl
03-20-2010, 03:32 PM
Well, manually installing latest FreeTDS (0.84)



./configure --prefix=/usr/local/freetds
make
make install


and adding



--with-mssql=/usr/local/freetds \


to /usr/local/directadmin/custombuild/custom/ap2/configure.php5
did the job.

WholesaleDialup
01-14-2012, 04:00 PM
Can anyone offer some connection string examples they used in PHP once getting this going? I am going to give this a shot but once done, not sure what's next in PHP. I am use to interfacing with MySQL only within PHP and I have done lots of work in the old days connecting to MS SQL from ASP. I am new to MS SQL from PHP so, any examples would be appreciated.

I see documentation and examples out there but I am not sure if they pertain to those that set it all up with TDS like this or some other method.

Do I just do something like this?


// Connect to the database (host, username, password)
$lnk = mssql_connect('localhost','UID','pass')
or die('Could not connect to the server!');

// Select a database:
mssql_select_db('dbname')
or die('Could not select a database.');

// Example query: (TOP 10 equal LIMIT 0,10 in MySQL)
//$SQL = "SELECT TOP 10 * FROM ExampleTable ORDER BY ID ASC";
$qryCust = "SELECT * FROM Customers";

// Execute query:
$qryRslt = mssql_query($qryCust)
or die('An error occured: ' . mysql_error());

// Get result count:
//$Count = mssql_num_rows($result);
//print "Showing $count rows:<hr/>\n\n";

// Fetch rows:
print "Starting loop";

while ($rowCust = mssql_fetch_assoc($qryRslt)) {

print "Cust: ".$rowCust['Customer']."\n";

}

mssql_close($lnk);

zEitEr
01-15-2012, 08:10 AM
@WholesaleDialup

Wrong forums. You might be luckier on specialized forums, search a link with help of Google.

NaSRi
02-01-2017, 05:34 AM
I had to install freetds-devel too because it includes libsybdb.so and it was necessary for installation also I had to create a symbolic link as following line

ln -s /usr/lib64/libsybdb.so.5.0.0 /usr/lib/libsybdb.so

NaSRi
02-01-2017, 05:34 AM
As it was pointed out by Jeff, MSSQL server is a Microsoft product thus only works on Windows.
The guide i posted back in september provides you with the means to connect to a MSSQL server from php on a Fedora core 4 OS which is not supported anymore and yum did not work for me.

In the meantime I installed CentOS 5 and I made it work like this:
1. Install freetds:

yum install freetds

2. Edit the php configuration file (i have apache 2 and php 5, change acording to your configuration):


mkdir /usr/local/directadmin/custombuild/custom/ap2
cp /usr/local/directadmin/custombuild/configure/ap2/configure.php5 /usr/local/directadmin/custombuild/custom/ap2

edit and add this line to /usr/local/directadmin/custombuild/custom/ap2/configure.php5:

--with mssql=/usr \
(Note: if you write this at the end of the file make sure you remove "" and add it to the line before it)

3. Rebuild php:


cd /usr/local/directadmin/custombuild
./build clean
./build update
./build php n


Again, this does not install MSSQL server on your Linux host (that is only posible with Windows), but merely provides you with the means to connect to an external MSSQL database.
Hope this helps.
I had to install freetds-devel too because it includes libsybdb.so and it was necessary for installation also I had to create a symbolic link as following line

ln -s /usr/lib64/libsybdb.so.5.0.0 /usr/lib/libsybdb.so