Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing PHP for multiple platforms & database question

Status
Not open for further replies.

bunnyweb

MIS
Jan 13, 2003
42
IE
Hello Everyone, I am hoping someone can help me out. I have 2 questions.

Question 1:

We have two web servers. Server 1 is a UNIX box running Apache. Server 2 is a Windows machine running both IIS and Apache. If I write a PHP script, will I be able to run that same script on both my UNIX web server and my Windows web server?

Question 2:

Is is possible to make a database connection in PHP from my UNIX web server to a SQL Server database located on our Windows server?

Any and all information would be greatly appreciated. Many thanks in advance.
 
A1: Unless the PHP script is doing a system-specific function, your script will work on any platform.

A2: Yes, if your SQL server is configured to allow connections from the address of the web server.

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
Thank you picklefish for answering my questions. Forgive me, but I just need to be clear on this...

So I can write a script, call is mypage.php. I can place the mypage.php file on both a UNIX box running Apache and a Windows machine running IIS and it will work on both platforms? That seems almost too good to be true. I would assume that there would be at least some changes to the code for connecting to databases, no?

And again, just to be clear, I could have the mypage.php script running on my UNIX server and connect to say a MS Access database located on a Windows server (in the same network of course)? Would I need to install and/or configure anything extra for this to work properly?

Thanks a mill for the help!
 
1. If you use file paths make sure you use the correct slash which I belive is the one below on the ? key.

2. are you wanting to run the script (which really is fine, i develop on windows and deploy on linux) to access the same data base type or does it differ between dev and production for example using mysql in dev and sqlserver in prod. If you are you might have to use the PEAR database abtraction class or ODBC or write you own routines. The connection strign will be differecnt because of ip address dtabse name user name passwords etc.

However you mention Access. I can't think that you will be able to get to an access database from Unix unless you have an ODBC driver (or equivilent) on Unix (which I would be supprised to see in fact). Alternativly you might have to write a PHP extention to access MSAcess or the easier route a set of web services running on the windows machine which expose interfaces via SOAP. Even with SQLServer from Unix will requre a driver on the Unix machine which may or may not exist. Ask in the SQLServer forum about Unix drivers (actually the sybase driver many work)

Hope this isn't confusing, if you have PHP and MYSQL on windows and Unix it all works realy well.


 
Thank you ingresman for responding to my post. Let me explain my mad reasoning for my questions, and hopefully you can help enlighten me a little further.

My company developes client/server applications and we are building web modules that work along side these applications (they basically share a database). The web modules that I'm supposed to be writing will be distributed to different companies, each with their own unique web structure in place. So it could be possible that the same application at company A will be running on a Linux web server connecting to a SQL Server database, whereas company B may be running IIS with MS Access.

I am hoping to find a solution where I only have to write one web application that can be used on as many platforms and configurations as possible.

My biggest concern is the database connectivity. I keep coming up against the problem that the company has a UNIX web server, but the database that our client/server application uses is usually SQL Server or MS Access, residing on a Windows machine. How can I get around this?

Thank you so much for your help!!
 
I would think the best bet is to use ODBC as your common interface to all databases. This would mean that the calls you make in PHP modules will be the same regardlesss of the database at the back (in theory). You may have to tweak the SQL for differecnt databases. The tweaking would be done in functions write e.g your_company_Execute_SQL which would pick up from a configuration file the target database and tweak SQL as it needs e.g. if $backend = "oracle8i" $sql = "... or if $backend = "mysql" $sql = "... You get the picture. A major advatage to using ODBC is that the back end database can by anything that a driver exsits for so if a company in the future wanted Oracle ir Inforix, no probelsm your main code does not have to change.

The big problem is seeing the database in the first place especially when its Aceess. Microsoft sont document the access forat so no one can has written a driver (i might be wrong here) for non Windows platforms. If the end service was always on windows you don't have a problem.

What I suggest you do is look at a company called They have drivers for just about every database and they run on Unix. Have a look at the web site for details and platforms. Interesting they do a product called odbc-odbc bridge which may be the answer to the access problems, where I would imagein what happens isyou make a call to the bridge and it goes off to the windowes machines and does the maghic. Id be interested in how it does it.
openlink also support the iodbc standard which is situated at Have a look at this solotuion (and also from merant) which might be the answer your looking for.

If you get ab solutoly nowhere I would look at the SOAP documentation and create some web services which run on the windows machine (possibly with xitami/php) which does the calls to access and givesd you just XML back. This would be an interesting abstraction project in its own right.

Anyhow, check put the stuff I mentioned here and have a read and post back here after you've digested it.

Kevin
 
The typical way to configure scripts to work anywhere is to require a separate configuration file. For example, your mypage.php (and any other page that calls the database) would start out with...

Code:
<?php 
require (&quot;config.php&quot;);
//...

You would define all of your database connection variables and system file paths in the config.php file. This allows you to tweak one configuration file and make your entire library of PHP pages instantly transfer to another environment.

I'm still a little lost on how your servers will function. If you cannot (for some bizarre reason) have the UNIX server make a DB connection to a remote database server (which is done all the time), you could set up a http server on the database server to dish out the content. With PHP, it is possible for one http server to read the data from another http server, and present it to the client as its own data.

You might want to browse phpclasses.org (or your favorite PHP script example repository) for database abstraction examples for different databases.

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
Jim,

Do you know if the sqlserver library on Unix supports the network protocol (TDS) or do you have to install some conectivity software ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top