Ask the Informix Pro 10-Minute Solution

Web Access to Informix via ODBC
By Joe Lumbley

I've noticed that many Ask the Pro questions in this and other DevX forums relate to interfacing Informix database engines to the Web. This 10-Minute Solution shows you how to establish database connectivity to Informix through HTML, the language of the Web.

The Web and e-commerce are exposing many people to databases who otherwise would not be dealing with them. As the politicians are so fond of saying, the database tent is getting bigger as we begin to assimilate new users, new concepts, and new applications into the Informix community. Many of these new users are not your typical database specialists who are used to some of the arcane tricks that us "old-timers" have developed over the years. They have been raised on drag-and-drop methods and live for their graphical user interfaces. I hope this article will demystify some of the steps needed to set up a system to access the database through the Web.

Depending upon several factors, this can either be an incredibly simple or an incredibly difficult task. In the newer Informix engines such as Internet Foundation.2000, the Web interface is built into the engine or added in through Informix DataBlade modules. These techniques integrate HTML with Informix and can allow the developer to store entire Web pages or entire Web sites in the database itself. Since these products are relatively new, there aren't that many people using them now, so I'll concentrate on some of the more popular versions. I'll also concentrate on Windows-based applications for clients, rather than UNIX-based applications, for the simple reason that they're a lot more common.

You need several things in place in order to access Informix database data from the Web. First, you need a Web server. If you have a Windows 98 system, you may already have one installed, especially if you have Web development tools on your system. If you don't have a server available, you can download one from the Microsoft site. Microsoft provides their Personal Web Server (PWS) for free. This Web server is also contained in the Windows 98 CD-ROM. Setup is a snap; just follow the instructions. This is not a heavy-duty server, but it's more than adequate for light usage such as testing and some intranet applications. Once the Web server is up, running, and tested, the first step is in place.

You should also have a Web development tool on your system. Sure, you could write HTML by hand, and for a simple task such as this demo doing it by hand is possible, but it's a waste of your time. If you're doing Web work, a development tool is almost mandatory. I personally use Microsoft FrontPage 98, which is inexpensive, fairly robust, and easy to use. This article assumes that you're using FrontPage. It will make the Web-side connectivity much easier. The methods will be similar for other tools, but they each do it differently.

Your Web server also needs connectivity to an Informix database. This database can either be located on the Web server machine or on a different server. My demo will be done on a Windows NT 4.0 system running Informix IDS 7.30 being accessed from a Windows 98 Web server. Connectivity between the Web server and the database server can be either an Informix Connect link to the database or an ODBC connection that may or may not run over Informix Connect, depending upon the ODBC vendor. Most will use Informix Connect with ODBC. Informix-supplied tools may simply use the Informix Connect link and not use ODBC. ODBC will give you the most flexibility, so I'll be examining a connection over ODBC.

Depending upon your version of Informix, you may already have ODBC installed. If you don't, you need to get it. Informix's version of ODBC is called Informix-CLI (for "call-level interface") and is included in many of the Informix CD-ROM products. To check whether you have CLI installed, click Start | Settings | Control Panel | ODBC Data Sources. Choose the Drivers tab and see whether you have a driver for your Informix engine. If you see Informix 2.80 (32-bit) or Intersolve 3.01 (32-bit) on the list, you have the Informix ODBC.

If you don't have CLI installed, it can be downloaded for free from Informix's electronic distribution partner, Intraware. Scroll down the right-hand menu bar until you see "Free Informix Software" and then click on ODBC Driver.

Setting Up the ODBC Connection
Informix ODBC relies upon Informix Connect for its connection to the database. The first step is to ensure that your Web server has an I-Connect link to the database server. On Windows systems, this is handled by the setnet32 Informix application. Since this is needed for any type of remote access to an Informix database, I'll assume that you understand the process of setting up an Informix client. If not, check with your DBA or system administrator. After being set up with setnet32, the connection is usually tested with the Informix ilogin utility. Once you can ilogin to a remote database, you are ready to set up the ODBC data source.

Depending on your installation, you may have a menu item for ODBC/CLI under your Informix menus. If not, you can access ODBC through the Control Panel. Go to Start | Settings | Control Panel | ODBC Data Sources (32-bit). The first three tabs are for Data Source Names (DSNs). There are tabs for User DSNs, System DSNs, and File DSNs. You want to create a System DSN for Informix, so choose the System DSN tab:

Click on the Add button to add a new DSN. You'll get a screen showing available drivers:

Choose the INFORMIX 2.80 32 BIT driver, and click the Finish button. The setup screen will appear:

Fill out the required values (top portion) with the information about your destination database and server. Call the data source name anything you want; the rest of the items are the same as you would fill out for setnet32. In the second section, fill out the UID (user name) and PWD (password) for your Informix user. The rest gets filled in automatically. Click OK to complete. Your new data source name will show up in the System DSN tab.

Testing your ODBC connection is not part of the setup and it usually entails cranking up an ODBC application to see if it works. There's nothing like Informix's ilogin program to test the connectivity. One good application to use for this is the WinSQL program, which is available for free download from the International Informix Users Group site.

In addition to being a good way to test your ODBC connectivity, WinSQL is a very capable SQL editor and query manager. It's well worth your time to download. Once your ODBC connection is established and tested, you have the pieces in place to access your database from the Web.

Building the Web Page
The first step is to make sure your Web server is running and check out where it is placing files. The Microsoft PWS installation places a menu item in the Start menu as well as an entry in the Control Panel. Since I've seen both the Start menu item and the Control Panel entry disappear for whatever unfathomable reason Microsoft has concocted, I'll show you how to do it from the command line.

First, go to Start | Find. Do a search for the name "pws" on all of your local drives. PWS is usually placed in c:\windows\system\inetsrv\pws.exe. Once you find the pws.exe file, it may help to right-drag it to your Desktop so that you create a shortcut to it. Starting the pws.exe program gives you this screen:

If the server is not running, start it with the Start/Stop button. The other thing to look for is the home directory for the Web server. In my case, it is d:\inetpub\wwwroot. Yours will probably be different. Once the server is running and you know where its files are kept, close the Personal Web Manager.

Now, open Microsoft FrontPage and either create a new Web page or open an existing one. Go into the Folders View and see if you have a folder in the Web that is suitable for running programs. You will be creating an Active Server Pages (ASP) page in FrontPage 98, and Web security requires that such pages be located in a folder that allows running programs. This folder is commonly called cgi-bin. If there's no cgi-bin directory in your Web, create it:

Right-click on the folder in FrontPage Explorer and choose Properties. This brings up the Properties dialog box:

Click OK and you will now have a secure location to store your Active Server Pages.

Go into the FrontPage 98 Navigation mode and choose the page you want the database information to reside on. Mine is on the Informix page of the demo Web. From the FrontPage 98 menu bar, choose Insert | Database | Database Region Wizard. The following screen appears:

Enter the name, user ID, and password for the ODBC data source and click the Next button:

Here enter the SQL query for your page and click Next. You'll then get the following screen:

The query field name is the heading name for the query items in the database. Enter one query field name for each column to be returned from the database. Here I'm only querying one field, so there's only one field name. Click Finish. Your Web page now has an embedded table:

The final step is to save this page in your cgi-bin directory with the *.asp file extension. Use File | Save As to save the page in *.asp format.

If you now view the Web page, you should see the results of the query in the table. This does not work from within FrontPage; the page has to be viewed in a browser for you to see the data.

Like almost everything else in the database connectivity business, getting set up for the job is three-quarters of the work. Once you have all the pieces in place, running SQL queries becomes almost a trivial task.

Of course, there are many other ways to accomplish this task. Another method is to use the Perl programming language with the DBI extensions to use Perl to directly access the database. Various other tools are available, and they'll all handle the client/side work differently, but this 10-Minute Solution should at least give you a general outline of how to do it.

 
Other 10-Minute Solutions
 Writing Procedural Code in Non-Procedural SQL
 Web Access to Informix via ODBC
 Accessing Informix from Microsoft Access
 Database Administration Over the Web: Installing Informix Server Administrator
 Using Informix Server Administrator
 Customizing Informix Server Administrator
 WinSQL: Non-Informix Tools to Access Informix Databases
 Installing and Testing JDBC for Informix Systems
 Using Informix's "First N" Construct in SQL Statements
 Date and Time Manipulation in Informix
 Parsing ASCII Files Elegantly Using SQL
 Hardening Your Informix Database System
 Keeping Your Informix rootdbs Lean and Clean
 Physical Design Issues for Large, Growing Database Systems
 Install and Set Up Server Studio JE for Informix




Sponsored Links


Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers