Use Delphi to develop Web (3) Dynamic scripts and use databases

Source: Internet
Author: User

Set and register the Database Access Control in the main program. It is very easy to use the database in the script.

The following script can be used to access the database.

<%
Uses sysutils, classes;
VaR
Aaa, rndnum, BB: string;
I, num: integer;
 
Begin

With CX do
Begin
SQL. Clear;
SQL. Add ('select * from soft ');
Open;
While not Cx. EOF do
Begin
Print (fields [2]. asstring );

Print ('<br> ');
Next;
End;

End;
End.
%>

To achieve database access, we use the database access control of devart. The company has a separate access

Controls for Oracle, SQL Server, My SQL, and InterBase, as well as Unidac controls, can simultaneously access the databases including

Other databases, such as DB2, access, and sqllite. The databases produced by this company access the database very quickly and stably.

It is updated quickly and can quickly support the latest database system. In particular, for Oracle support, you can directly use the TCP/IP protocol.

Connecting to the Oracle database saves the trouble of installing the client, so that the Web server can achieve almost zero configuration. Original Delphi cave

Is to use odac to connect to Oracle 11 GB.

After confirming the database access control, we can set and process the database access function in webbroke.

Put a torasession in the webbroke settings interface and set it to allow access to your database.

And define two new classes.

Type
Twebquery = Class (toraquery );
Twebsql = Class (torasql );
These two classes are used to replace them with other database access controls at any time to ensure that the scripts do not need to be modified.

It can run normally.

Add twebquery script registration to Initialization

G_unitlist: = tunitlist. Create;
G_unitlist.addclass (twebquery );
G_unitlist.sort;

Registerunits (g_unitlist, globalimporttable );

Generate two twebqueries in the webmodule creation event to facilitate direct use in the script.

Procedure TWM. webmodulecreate (Sender: tobject );
Begin
SCX: = twebquery. Create (Self );
Zcx: = twebquery. Create (Self );
SCX. Session: = dBs;
Zcx. Session: = dBs;
End.

The instance can be accessed when the script is running before the script is interpreted.

Show. webscripter. scripter. Reset;
Show. webscripter. scripter. registervariable (0, 'request: twebrequest; ', @ request );
Show. webscripter. scripter. registervariable (0, 'response: twebresponse; ', @ response );
Show. webscripter. scripter. registervariable (0, 'wm: TWM; ', @ self );
Show. webscripter. scripter. registervariable (0, 'cx: twebquery; ', @ SCX );
Show. webscripter. scripter. registervariable (0, 'zcx: twebquery; ', @ zcx );

Basically, you can directly access the database in the script.

Use the following URL to access http: // 127.0.0.1/Web? Path = test

By default, the system can directly use a query control, CX and zcx.

If you need more queries, you can directly use

Myquery: = WM. newquery;

Free is not required after use, and the system will automatically destroy these objects after execution.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.