how can i build php with MS SQL support

limpangel

Verified User
Joined
Apr 15, 2008
Messages
16
Location
Romania
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
 

limpangel

Verified User
Joined
Apr 15, 2008
Messages
16
Location
Romania
resolved

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.
 
Last edited:

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
Because MSSQL is a Microsoft product. It doesn't work on either Linux or FreeBSD.

Jeff
 

limpangel

Verified User
Joined
Apr 15, 2008
Messages
16
Location
Romania
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:
Code:
yum install freetds
2. Edit the php configuration file (i have apache 2 and php 5, change acording to your configuration):
Code:
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:
Code:
--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:
Code:
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

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
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

Verified User
Joined
Feb 16, 2006
Messages
307
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

Verified User
Joined
May 17, 2008
Messages
36
Code:
--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..
 
Last edited:

tundasrl

Verified User
Joined
May 17, 2008
Messages
36
Well, manually installing latest FreeTDS (0.84)

Code:
./configure --prefix=/usr/local/freetds
make
make install
and adding

Code:
--with-mssql=/usr/local/freetds \
to /usr/local/directadmin/custombuild/custom/ap2/configure.php5
did the job.
 

WholesaleDialup

Verified User
Joined
Sep 25, 2004
Messages
132
Location
San Antonio, TX
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?
Code:
// 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

Super Moderator
Joined
Apr 11, 2005
Messages
14,243
Location
GMT +7.00
@WholesaleDialup

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

NaSRi

Verified User
Joined
Aug 16, 2014
Messages
78
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

Verified User
Joined
Aug 16, 2014
Messages
78
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:
Code:
yum install freetds
2. Edit the php configuration file (i have apache 2 and php 5, change acording to your configuration):
Code:
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:
Code:
--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:
Code:
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
 

orkinoks

Verified User
Joined
Dec 24, 2010
Messages
64
Here is how it worked for me on centos 7 with php 5.4 ap2

yum install freetds unixodbc unixodbc-devel -y

add the following lines to /usr/local/directadmin/custombuild/custom/ap2/configure.php54

--with-pdo-dblib=/usr/local/freetds \
--with-pdo-odbc=unixODBC,/usr/ \

rebuild php with custombuild.

example connection string :


echo "<pre>", print_r(PDO::getAvailableDrivers()), "</pre>";
try {
$hostname = "[server_ip]";
$port = 1433;
$dbname = "[dbname]";
$username = "[username]";
$pw = "[pass]";
$dbh = new PDO ("dblib:version=7.0;charset=UTF-8;host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
 
Last edited:

ikkeben

Verified User
Joined
May 22, 2014
Messages
713
Location
Netherlands Germany
Here is how it worked for me on centos 7 with php 5.4 ap2

yum install freetds unixodbc unixodbc-devel -y

add the following lines to /usr/local/directadmin/custombuild/custom/ap2/configure.php54

--with-pdo-dblib=/usr/local/freetds \
--with-pdo-odbc=unixODBC,/usr/ \

rebuild php with custombuild.

example connection string :


echo "<pre>", print_r(PDO::getAvailableDrivers()), "</pre>";
try {
$hostname = "[server_ip]";
$port = 1433;
$dbname = "[dbname]";
$username = "[username]";
$pw = "[pass]";
$dbh = new PDO ("dblib:version=7.0;charset=UTF-8;host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
UH a online server with PHP 5x ? even worse 5.4x :eek:

for php 5.6x there are backported security updates for some repo's

i mean my reply well...

pdo is better ok... yup
 

orkinoks

Verified User
Joined
Dec 24, 2010
Messages
64
There are 10 year old sites on the server :)

UH a online server with PHP 5x ? even worse 5.4x :eek:

for php 5.6x there are backported security updates for some repo's

i mean my reply well...

pdo is better ok... yup
 
Top