With the development of Internet applications, the homepage is no longer just an enterprise information window. Many of the company's businesses can be realized through the INTERNET. For example, customers can order through the supplier's homepage, and the company can collect customer information through its own homepage. Feedback information, etc. On the other hand, with the development of the company's business and the expansion of geographical distribution, it is no longer possible to establish a simple local area network between the head office and its subsidiaries. At this time, the Internet can be used to realize the communication between the subsidiaries and the head office. Business processing is implemented using the currently popular enterprise application solutions, namely NCA structure and 0-client solution. Therefore, how to dynamically connect your homepage to the database and how to manipulate the records in the database in real time through the operation of the homepage has become a very important topic. Here are several methods to solve the dynamic connection between the home page and the database.
First of all, in order to enable you to operate the computer while reading the following introduction, you need to make the following preparations on Windows 95 or Windows NT.
1. Create the ACCESS database, c:my documentsmydata.mdb.
2. Create the table mytable (a dblong, b dbtext, c dblong) in the mydata database and add an appropriate amount of test data.
3. Establish a system DSN (database source name), set it in the ODBC control panel, name the data source ACCESSMDB, and point it to the newly created mydata database.
4. Install PWS (Personal Web Server), which is located in the addonspws directory of the Windows 98 CD.
5. Use frontpage to create a new Web on PWS, such as http://yourhostname/myweb . By default, yourhostname is your host name.
6. Use frontpage software to open the newly created myweb, create a new subdirectory scripts, and then set scripts as an executable subdirectory.
At this point, if your settings are correct, you can open Internet Explorer (hereinafter referred to as IE) and type http://yourhostname/myweb/scripts in the address bar. You will see the following prompt:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed
This is because the directory does not have a default html file (usually default.htm), and the directory is not allowed to be listed, but this shows that your pws settings are correct. Let’s introduce the first production method.
one. Use the Frontpage Database Region Wizard to complete the settings
. Open Frontpage, enter the already built Web, myweb, create a new page newpage1, and edit it.
·Click "insert" in the menu bar and select "database", "database region wizard", and a dialog box will pop up.
·In the input field under "odbc data source name", enter the created DSN, namely Accessmdb, and then click the Next button to proceed to the next step.
·Input select a,b,c from mytable in the input field under "Enter the sql string for the query", and then click the Next button to proceed to the next step.
·Click the Add button, enter the field name a in the input field under "enter the name of a query field to be added to the list", and then click the Ok button.
·Repeat the previous step and add both fields b and c to the query list.
·Click the Finish button.
·At this time, the system will prompt you to save the page in the executable directory and change the extension to *.asp. Follow the prompts to move newpage1.htm to the scripts directory and rename newpage1.htm to newpage1.asp. .
Enter http://youhostname/myweb/scripts/newpage1.asp in the IE address bar and press Enter. You will see the experimental data in the database displayed.
This method is simple to operate, but it is inflexible. The generated HTML file has poor readability and it is not easy to add secondary links.
two. Directly call HTTPODBC.DLL (IDC/HTX)
HTTPODBC.DLL is called Internet Database Connector and is an ISAPI (Internet Server Application Programming Interface), which accesses the database by calling ODBC.
This approach involves three main documents:
1.
After installing PWS, the
httpodbc.dll
file is placed in the windowssysteminetsrv directory.2. IDC file
IDC file is a text file with the extension IDC (Internet Databse Connector). It contains the necessary information, SQL statements, template file names, etc. for connecting the HTML file to the database.
File format: name: value, where name is the project name, such as datasource, template, sqlstatement, username, password, etc.
Project description:
datasource: data source name, that is, the data source name (system DSN) created in ODBC in the control panel.
Template: Template file name, which should be located in the same executable subdirectory as the IDC file.
Sqlstatement: The SQL statement to be executed.
An IDC file must contain at least three items: datasource, template, and sqlstatement.
3. HTX file
is an html file with the extension HTX (HTML Extension File). It is the format description of the records in the database returned to the page.
Format description:
<%begindetail%>: The starting position when returning multiple records.
<%endetail%>: The end position when returning multiple records.
<%fieldname%>: The returned field name representation method.
4. For example
, use notepad to create a new file with the following content:
datasource:accessmdb
template:myhtx.htx
sqlstatement:select a,b,c from mytable
. Save the file to the scripts directory with the name myidc.idc.
.Use notepad to create a new file with the following content:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Home Page</title>
< /head>
<body>
<table border="1" width="100%">
<tr>
<th width="30%" align="center">A</th>
<th width="30%" align="center">B</th>
<th width="40%" align="center">C</th>
</tr>
<%begindetail%>
<tr>
<td width="30%" ><small><small><%a%></small></small></td>
<td width="30%"><small><small><%b%></small></ small></td>
<td width="40%"><small><small><%c%></small></small></td>
</tr>
<%enddetail%>
</table >
</body>
</html>
.Save the file with the name myhtx.htx, and save the above file to the scripts directory. Enter http://yourhostname/myweb/scripts/myidc.idc in the address bar of IE and press Enter to see the returned record.
This method seems cumbersome, but it is extremely convenient to use. In fact, you can make a query in the database and copy the correctly generated SQL statement to the sqlstatement project of the IDC file. On the other hand, you can use a page editor (such as Frontpage) to create a format page, then copy the generated html file to the HTX file, and then modify it slightly according to the format requirements of the HTX file to become a standard HTX file. .
In addition, IDC files and HTX files are highly readable. You can modify the HTX file to generate secondary links, that is, link to different IDC or HTML files according to the returned records, such as:
<tr><A href="< %a%>.htm"><%a%></A></tr>
In this way, a secondary link is formed in the returned table. Depending on the value of field a returned, it can be linked to different a.htm file.
three.
The key point ofusing ActiveX components to create dynamic Web pages
is to first use VISUAL BASIC 5.0 or VISUAL C++ to create ActiveX components on the Web server, and then call OLEISAPI.DLL to access the database. Its advantage is that it is very flexible to use. Summary (total or subtotal) can be added to the output HTML file, and fields can be output in the specified format.