I. Various solutions to the web database
There are currently a variety of technologies for accessing the web database in a Windows environment, mainly:
1. Community Gateway interface CGI (Common Gateway Interface)
CGI is an earlier implementation technology. Suitable for multiple server platforms such as UNIX, Windows, etc., but CGI development
High cost, difficulty in maintenance, limited function, does not have transaction processing, and take up more server resources.
2. Internet Database Connector IDC (Internet Database Connector)
IDC integrates in the ISAPI (Internet Server API), fully utilizing DLL technology, easy to expand, but programming
Compared with CGI, it is more complicated and applies only to small database systems.
3. Advanced Database Connector ADC (Advance Database Connector)
The ADC provides ActiveX Control to access the database, and its main feature is that the data query is browsing by the user.
Execute, there is a need to download some of the partial records in the server-side database to the user end, the system is over-selling, slow response
Only for special frequent database query operations.
4. Java / JDBC language programming
The Java language is an object-oriented, easy to transplant, multi-threaded language, can connect to the database via JDBC
. The software written in Java / JDBC is strong, suitable for a variety of operating systems, but it performs efficiency and execution speed.
Not ideally, there is currently unable to establish efficient and high speed applications.
5. Dynamic server page ASP (Active Server Page)
ASP is Microsoft's latest web application development technology, focusing on processing dynamic web pages and web databases.
Hair, flexible, simple, high performance, is the best choice for accessing the web database.
II. Introduction to ASP
1.ASP Access the principle of the database
ASP is a server-side script execution environment that can be used to generate and perform dynamic high-performance web server programs
.
When the user requests the ASP home page using the browser, the web server responds, call the ASP engine to execute the ASP file.
And explain the scripting language (JScript or VBScript), connect the database via the ODBC, by the database access group
Part ADO (ActiveX Data Objects) completes database operations, and finally ASP generates HT containing data query results.
The ML home page returns the user-end display.
Since the ASP is running on the server side, the results return to the user browser in the form of an HTML home page, so the ASP source
The order does not leak, adding the security confidentiality of the system. In addition, ASP is an object-oriented script environment, users can
Increase the ActiveX component to expand its function, expand application scope.
2. The structure of the 2.asp page:
The ASP program code is simple, universal, file name is ended, and the ASP file is usually composed of four parts:
1) Standard HTML tag: All HTML tags can be used.
2) ASP syntax command: ASP code in the <%> tag.
3) The server-side include statement: can use the #include statement to transfer other ASP code to enhance the programs
active.
4) Script language: ASP comes with JScript and VBScript two scripting languages, adding ASP programming capabilities,
Users can also install other scripting languages, such as Perl, REXX, etc.
3.ASP's operating environment
The current ASP can run in three environments.
1) Windows NT Server 4.0 Runs IIS 3.0 (Internet Information Server).
2) Windows NT WorkStation 4.0 Run Peer Web Server 3.0 or more. 3) Windows 95/98 runs the PWS (Personal Web Server).
Among them, the IIS function on NT Server provides the strongest support for ASP, which is created to create high speed, stable.
The best choice for the ASP homepage.
4.ASP built-in object
The ASP provides six internal construction objects for users directly:
1) Application object: responsible for managing all session information, available to all specified applications
Share information between households.
2) Session object: Store session information of a specific user, only by the user, when the user is in different web pages
When jump, the variable in the session is saved during the entire session of the user. SESSION object requires a cookie support
hold.
3) REQUEST object: The information passed from the user end to the server, is the main method of the ASP read user input
.
4) Response object: The server sends the output content to the user.
5) Server object: Provide access to the server about methods and properties.
6) Object Context object: Added objects for IIS 4.0 for transaction processing. This function needs
Support for MTS (Microsoft Transcation Server) management.
5. ASP's main built-in component:
1) AD Rotator Components: Used to automatically rotate the advertisement on the same page by specifying the same page, used for WWW last day
Beneficial advertising services.
2) Browser Capabilities Components: Determine the functional data of the user browser that accesses the web site, including
Type, performance, version, etc.
3) Database Access Components: Provide ADO (ActiveX Data Objects) to access the number of support ODBC
According to the library.
4) File Access Components: Provide read and write functions for server-side files.
5) Content Linking Components: Generate the list of contents of the web page, and connect each page to make navigation
Strip.
In addition, components such as MyInfo, Counters, Content Rotator, Page Count are also installed.
Actiive components can be prepared from your own to improve the practicality of the system.
6. Database Access Components ADO
The application on WWW is to access the web database. When using the ASP to access the web database, you must use the ADO components.
ADO is an ASP built-in ActiveX Server Component, through the web server
Set ODBC and OLEDB to connect multiple databases: such as Sybase, Oracle, Informix, SQL Server, ACC
ESS, VFP, etc., is the most effective and simple and straightforward approach to the database supported by Microsoft.
The ADO components provide the following seven objects and four collections to access the database.
1) Connection object: Establish a connection to the background database.
2) Command object: Execute SQL instructions to access the database.
3) Parameters object and Parameters collection: Provides data and parameters for Command objects.
4) RecordSet object: Store data information after accessing the database is the most frequently used object.
5) Field object and field collection: Provide the work of accessing the various fields of the current record in the Recordset
can.
6) Property objects and Properties collection: Provides information for Connection, Command, Recordset, Field objects.
7) Error object and Errors collection: Error information when accessing the database.
3. ASP Access Database Step
In ASP, use the ADO component to access the background database, you can use the following steps:
Define data source
Open the Control Panel on the web server, select "ODBC", select "Add" to "System DSN",
Select the type of database, name, location, etc. you want. This article defines "SQL Server" and the data source is "HT"
The database name is "HTDATA", and the scripting language uses JScript.
2. Use the ADO component to query web databases
1) Call the server.createObject method to obtain an instance of "AdoDb.Connection", then use Open
Method Open the database:
Conn = Server.createObject ("AdoDb.Connection")
Conn.open ("ht")
2) Specify the SQL command to be executed
After connecting the database, you can operate, such as query, modification, deletion, etc., these are all through SQL instructions.
Completed, if you want to query the code containing "X" in the data table signaltab
SQLSTR = "SELECT * from sign thealtab where code like '% x%'"
RS = conn.execute (SQLSTR)
3) Use the RecordSet attribute and method, and display the result
In order to more accurately track data, create a cursor containing data with the RecordSet component, the cursor is stored
Data in memory.
RS = Server.createObject ("AdoDb.Recordset")
RS.Open (SQLSTR, CONN, 1, A)
Note: A = 1 read
A = 3 new, modified, delete
In Recordset components, common attributes and methods are:
Rs.fields.count: The number of fields of the Recordset object.
RS (i) .name: The name of the i-th field, i is 0 to rs.fields.count-1
RS (i): Data of the i-th field, i is 0 to rs.fields.count-1
RS ("Field Name": Specifies the data of the field.
Rs.Record.count: The total number of data records in the cursor.
Rs.eof: Whether the last record is recorded.
Rs.MoveFirst: Point to the first record.
Rs.MoveLast: Points to the last record.
Rs.MovePrev: Refers to a record.
rs.MoveNext: Note the next record.
Rs.Getrows: Place the data in an array.
rs.properties.count: ADO's ResultSet or Connection attribute bit.
Rs.properties (item) .Name: The name of the ResultSet or Connection of ADO.
Rs.properties: The value of the ResultSet or Connection of ADO.
rs.close (): Turn off the connection.
4) Turn off the database
CONN.CLOSE ()
IV. Query the web database
The sample program below is the SignalTab table that accesses the SQL Server database, three fields in the table: CO
DE (Code field, character, 3), class (Classification field, character type, 10 bits), MEMO (note field, character type, 20). Data Source DSN: HT, User Name: Client, Password: Passwd.
Screen input page Input.asp
<% @ Language = javascript%>
hEAD>