473,721 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

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 3636

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

Similar topics

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). I don't want to check a cerificate, so i simply tried a from OpenSSL import SSL
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 from All-Around-Software. I try to connect and I get an error message ORA-12545 "Connect failed because target host or object does not exist".
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 have chosen red hat linux. However, I'd like to keep a small database on a sql server as a datasource. However, this sql server is already part of our organization's windows domain. I suspect I'll need to configure samba so that other terminals...
by: kamilla | last post by:
I have a mysql 3.5 server installed on a suse linux 8.1, with address Now I want to access that db from a W2K pc, address I am able to ping, but I cannot connect to the db, and get error 2013. I have tried with MySQL Administrator 1.0 and also with ODBC. The db on linux has grant all on *.* to ''@'10.0.0.%' and also tried .... to root@ and others seen on posted messages. I can access that db...
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 both the iis and sql server in a single machine. Not too long ago, the machine had some hardware problems, and management has decided to purchase new servers, for both asp.net and sql server.
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 service, however this is not difficult since I already have the API's to do this. Unfortunately I can't find anything about this subject, so I am afraid that it can't be done... TIA,
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 convert the database connection code to connect to the database on another Linux server. I see alot of information on Perl DBI CLI and PHP DBI CLI but cannot find any examples of Korn Shell connecting to a database on another server. Is there...
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 60003/tcp
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 to connect to the remote host using a simple connect statement, DB2 hangs. The connection statement I'm using (I've obviously obscured the parameter names): $ ./db2 connect to DATABASENAME user USERNAME using PASSWORD;
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.