473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Considerations on Connecting to MS SQL Server from PHP/Linux

After a lot of thought and research, and playing with FreeTDS and
InlineTDS, as well as various ODBC connections, I have determined that
the fastest and cheapest way to get up and going with PHP on Linux,
connecting to MS SQL Server, unless it was already pre-installed by
your Linux installation, is to build your own multithreaded TCP socket
server on Windows and connect to it through the socket API in PHP on
Linux (if you have installed that). I noticed that RH9 comes with PHP
4.2.2, but it doesn't come with the MS SQL connections. It does come
with MySQL and PgSQL connections, as well as socket API.

I previously had a lot of trouble building just the loadable PHP
modules for MS SQL Server. I could get them combiled for 4.3.x, but
then I couldn't load them in PHP 4.2.2 because I guess it was a
version conflict. I was faced with having to recompile and reinstall
PHP entirely on the latest stable version 4.x.x, and I feared this
would affect my already existing code I had written. I had no problem
installing InlineTDS or FreeTDS, then connecting them through to MS
SQL Server with the command-line tools, but getting PHP to talk to
that was looking to be near impossible. The same with ODBC on Linux.
In fact, there is no more discussion with me on this. After a month of
frustation, I'm stubbornly not going back in this direction. My next
PHP upgrade will be with whatever Fedora Linux ships with (when the
RedHat Fedora project starts making stable Fedoras). If MS SQL API
works in that release, then I'll use it. Otherwise, I'll use a socket
server.

One can build this socket server easily in VB6 or C#.NET on the MS
platform. (Aside: With C# out, why would one ever use VB.NET in
VS.NET? VB is dead.) You build a knock-knock port on the socket
server, and then it chats back the port number it agrees to talk to
the client on. (Besides the main knock-knock port, you should stick
with a range and not go totally random in the 5000-65535 range.) You
then send the SQL (including EXEC for stored proc and stored proc with
parameter support), and it chats back either an error, number of rows
affected, or row- and column-delimited table data (with schema). The
socket server could open up an OLE DB connection via ADODB (or
whatever works best in C#.NET). When the PHP concludes, it sends a
close port request to the socket server and that port becomes
available again. The socket server should also be smart enough to
watch port traffic for long delays, shutting them down, and you might
want to build something that resets all ports at a certain time at
night.

Once I built this, I used the W2K Resource Kit tools (srvany, instsrv)
to load the socket server EXE as a service in the Services Control
Panel. I then built a scheduled task that bounced this service at
midnight with a net stop, net start script. I found that this also
worked on XP, even though I didn't have the XP RK.

Encryption is probably not a recommended option for sending back table
data, however, because of the tremendous speed impedement with that.
Your best option is probably to authenticate your user/pass combo,
then put a proprietary CRC check on the command request stream. If
either of those fail in the command request, then it's being hacked
and the program can automatically block that IP address via an update
to an INI file on the socket server's host. Another option is to
encrypt all command-requests, but send replies as unencrypted,
blocking any IP addr that fails to send proper requests.

Once this connectivity is achieved from PHP to the socket server, you
can build a wrapper that makes the API look similar to the MySQL API
in PHP.

I wrote this in a day and it came back with 4,000 records extremely
quickly. On a 100Mbs network, I don't notice any speed difference
between using a local MySQL server and using a remote MS SQL Server.
(Aside: Here's another interesting factoid -- when I started building
this, I mistakingly had the socket server on 10Mbps and it STILL came
back fast!) I wouldn't want to rely on it for more records than 4,000,
however. A web app should probably be redesigned if it's relying on
pulling back more than about 1,000 records at a time. Such a web app
should probably utilize a stored proc or a tighter query to reduce the
number of returned columns and records.

Using OLE DB on the socket server, I found no problem connecting to MS
SQL 6.5, 7, and 2K (on the latest security service packs, mind you). I
also had no problem calling stored procedures with or without
parameters because I used the EXEC statement to achieve it.

If you build one of these, later on you'll start to realize the
powerful opportunities here, such as making this a two-way bridge
between Windows and Linux to send/rcv XML data and all kinds of
encrypted command requests, not just for database data. On the Windows
side, you could have a COM or .NET object that uses sockets to
interact with a special PHP URL on Linux that you build to receive
command requests.

Happy sockets, y'all!
Jul 17 '05 #1
0 3610

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: christian_stengel | last post by:
Hi *, I have just started to learn python and I am having a problem with an python client connecting to a perl server using ssl (I tried this with pyOpenSSL and with the build in SSL Module). ...
1
by: Wayne Happ | last post by:
I'm a new Oracle user. I've installed Oracle 9i on a Linux RedHat machine V9.0 and it's running. I took a Windows XP machine and installed the Oracle client on it along with PL/SQL developer...
4
by: Dan | last post by:
Hi, I'm planning to develop a small intranet to provide our organization with documents online. I've decided to do this using jsp/servlets using a tomcat server. For an operating system, I...
3
by: kamilla | last post by:
I have a mysql 3.5 server installed on a suse linux 8.1, with address 10.0.0.100. Now I want to access that db from a W2K pc, address 10.0.0.200. I am able to ping 10.0.0.100, but I cannot connect...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
14
by: Arjan | last post by:
Is there a way to connect to the Linux filesystem with C# without using Samba? I need it to get a configuration file from the server, edit it and place it back. And after that I need to restart a...
1
by: mm | last post by:
I have several korn shell scripts I use with a MySQL database on the same server (Solaris). I am moving to a Linux environment where the MySQL database is on another server. I would like to...
10
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END...
1
by: malooga | last post by:
Hello, I'm having a problem connecting to DB2 on a remote iSeries host from a Linux server, both of which reside on my company's internal network. I'm using the IBM Linux Client V9.1. When I try...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.