Sei sulla pagina 1di 15

5.

16

More specifically, the ADO object model provides obijects and collections (i.e containers that hold one
or more objects of a specific type) as follows:

Object/Collection Description

Connection object This object connects us to the databases,

Recordset object This object allow us to work (read, modify, collect) with the data

In a table,as it contains a set of rows from a table.

Error object This object represents an crror generated by the data souree.

Field object This object represents a single column in the table

Command object This object provides another way to create a Recordset object.

Paramaters collection This collection contains paramenters needed by the command.

Thise parameters are stored in a parameter object.

Methods to access the contexts of a Database table are as follws:

Methods Description

Move Next This method helps us to move to the next record set.

Move Previous This method helps us to go back to the previous record on the

Recordset.

Move First This method helps us to the first record in the recordset.

Move last This method helps us to the last record in the recordset.

Move numbers This method helps us to go to the specified numbers of record

Form the current one.

BOF It is a Boolcan value that is True when you are still at the

Beginning of the recordset.

EOF It is a Boolcan value that is True when you reach the end of the

Recordset.
As Recordset object contains several set of record, we can access only one record at a time by using
above methods. The Recordset object maintains a pointer to the current record and we can move that
pointer forward or backward.

Suppose the following or backward.

TABLE 5.5 (i) Students Table.

Student Id Student Name Student Grade Branch


1201 Akbar A+ CSIT
1202 ibrahim A CSE
1203 Rinz A CSE
1204 Siraj B CSE
1205 Firdous A+ ECE
Now,write the following
program with the name Access Db asp to access and print the contents

Of

Students table from the database.

5.17

Program : AccessDb.asp

<%@LANGUAGE = VBScript%>

</- -#include file = “database Connect.asp”- - >

</- - #include virtual = “/adovbs.inc”- - >

<html!>

<body>

<%

Dim objRS

Set objRS = Server. Create Object (“ADODB.Recordset”)

objRS.Open “Student “.objConn. . . adCmdTable


Do While Not objRS.EOF

Response. Write “Student Roll Number;”&objRS (“Student Id”)”&”<BR>”

Response. Write “Name of Studentr:”&objRS (“Student Name”)”&”<BR>”

Response. Write “grade of student :”&objRS (“Student Grade”)”&”<BR>”

Response. Write “<p> <HR> <P>

objRS.Move Next

Loop

objRS.Close

Set objRS = Nothing

objConn.Close

Set objConn = Nothing

%>

</body>

</html>

In the above program, the following line includes the file that establishes the connection to the

Database:

<%

Dim objConn

Set objConn = Server. Create Object (“ABODB.Conection”)

objConn.Connectionstring = “DSN = hamedsufi.dsn”

objConn.Open

%.

The first and second lines in the above code creates the connection object which holds the

Information about the database we want to access.

The third line in the above code scts the connection string which tells the connection object
about using a system DSN. A system DSN the (Data Source Name) is a file that contains information

about the database such as where it is and what Kind of database it is.

5.18

The fourth line in the above code opens the connection


In the above program, the following line includes the fill with same of the ADO constants
<!--# include virtual =”/adovrbs.ine”-->
In the above program , the following two lines creates the Recordset object:
Dim obj Rs
Set obj Rs =Server . Create object (“ADODB. Recordset)
Then ,the following line opens it and fill it with all the records (rows) of the table students:
ObjRs.open “students”,objconn,..adcmdTable
The open method of recordset object accepts different sets of arguments as follows:
General syntax:
Recordset .open source ,connection, cursortype,locktype ,commandtype
 Source is a string
 Connection is a connection object
 Cursortype indicates whether you want to write or read ,Its default value is the ADO constant
adopenforward only
 Locktype indicates whether you want to write or read ,Its default value is the ADO constant
asopenforward only
 Command type indicates how the source string should be evaluated.
The ADO constant adcmdTable specifies that source should be evaluated as a table name.
Also , we can omit the cursortype and locktype because the default suit our needs
Now , in the above program , by using a Do-while loop, we write (prints)the data in the current
record each time by moving forward to the next record , until . We reach the end o f the
recordset . If no more records are in the set ,EOF will be set to true.
When finished accessing and printing the records , close the recordset, set it to nothing to fre
the memory associated with it. Then , close the connection , set it to nothing again to free the
memory associated with it.
Remember, always do it in this order only.
The output of the above program ,will print the connection of students table from database to
an ASP type.

5.6 CGI (COMMON GATEWAY INTERFACE)AND SERVER –SIDE DESIGN


The CGI(Common Gateway Interface) is a standard protocol (Gateway) through which users interact
(interface) with applications on web servers . That is CGI provides a way for clients (I,e through web
browsers) to interface indirectly with applications on the web server.
5.19

As CGI is an interface ,it cannot be programmed directly , so a script or


executable program called as CGI script must be written on web servers and
executed to interact with it. While CGI scripts can be written in many
programming languages , PERL (practical extraction and reports language)is
commonly used due to its power , flexibility and predefined programs.

CGI programming is all about creating and using CGI scripts. In PERL
programming , a CGI script is only a PERL program in a file with the
extension egi. The CGI script are placed on ISP (Internet service provider)
web servers and these scripts will create web pages dynamically using PERL
code (applications ) responding to user requests.

Figure 5.6 illustrates the interaction between client and server when the client
requests a CGI script CGI script process information like credit-card number
recived from a Form by verifying or rejected. Web server (usually Web –master
or the author of websites) executes CGI scripts (programs) upon client ‘s request
. These programs are saved with a certain filename and extension (Such as. Cgi
or .pt) within a special directory (such as cgi-bin) on web servers or any other
computer. Thus, after the application output is sent to the web server through
CGI , the result are sent to the client,

5.6.1 CGI programming (CGIScripts)

CGI Script are used in form processing and presenting Business Logic.

HTML froms are used to collect data from users and sent it to a web server for
validation processing by server-side program and scripts. This allows users to
register and purchase software products, credit-card validation etc. So. A
registration from could be used , by a software company to obtain profile
information of the user before allowing him to download software.

The following program generates an HTML from to collect data from user and
send it to web server for validation (Business Logic) by CGI Script:

Program : Restration From. Html

<html>

<head>

<title>

HAMEDSUFI presenting Registrantion Form to take user input in HTML

</title>

</head>

<body>
5.20

<H1> This is a sample registration from </H1>

User Information <br>

Please fill in all fields and click Register .

<form method = “post “ action = “/cgi-bin/Handle FromData . cgi”>

Form Name <input type = “text “ name = “Iname “ > <br>

Last Name Address <input type = “text” name = “imail”> <br>

Email Address <input type = “text name = “creadit”> <br>

Credit - Address <input type = “text” name = “creadit”> <br>

Credit – card Number must be in the form (555


) 555-5555. <br><br>

<input type = “submit” value = “Register”>

</form>

</body>

</html>

In the above [program , the <frorm> tag generates an HTML from , and when the user clicks register
button , the from information is to the server . The statement action = “/cgi-bin/Handle Form Data. Cgi”
directs the server to exeoute the HandleFrom Data cgi. CGI script located in cgi –bin directory to process
(validate) the posted from data, we have assigned unique names like fname , Iname , email creadit to
each of the CGI script Handle Handle FromData. Cgi which can then access the submitted value for
specific filed . The following CGI script (program) processes the data posted by previous HTML program
RegistrationFrom.html and sends a Web page response back to client .

CGI Script (program) ; HandleFrom Data.cgi

# ! /usr/bin/peer!

# HAMEDSUFI presenting CGI Script to read information from the Form .

Use CGI qw ( : standerd ) :

$ first Name = param (“fname”);

$ lastName = param (“Iname”);


$ last Name = param (“email”);

$ email = param (“credit”);

Print (H1”);

Print (“Thank you completing the registration form . “ br () );

Print (“ You have been added to the mailing list “);

Else

5.21

{ print (“INVALID CREDIT – CARD NUMBER”, br ( ) );

Print (“A valid creadit-card number must be in the form “, br ( ) );

Print (“(555) 555, 5555”, . br( ) );

Print (“Enter a valid creait – card number and rsubmit.”.br( ) ) ;

Print ( “ Thank you “);

Print
(</body> </html>);

In the above program , the use statement instructs PERL pfograms to include functions (modules ) of
predefined [packages. The CGI module, contains usful function for CGI scripting in PERL, include
functions that return strings representing HTML tags.With the use statement , we can specify the import
tag : standard to import a predefined set of standard functions .

Function param is part of the PERL (CGI) module and retriever value from a Form ‘s Input Fields.

We access the value entered by te user in the Form’s Textfieds (whose names are fname , Iname , email
and creadit ) by caling param (‘”fname “) , param (“Iname “) . param (“email”) and param (creadit “) and
keep the values returned in variables $ fname , $Iname , $email and $cridit of CGI script .

Remember , while creating dynamic web pages in PERL, we output HTML by using print statement The
print statement display s the result on the clint’s Web browser.

Next, we deletemine Whether the credit –card number entered by the clint is valid, The design of
verifying information is called as Bussiness Logie. This verification is done by if conditional statement The
expression “j\d(3) “, then it mathes the closing parenthesis by”\)” then three digits by “\[3] “. Then a
hyphen by – and at last it matches four digits by “\d[4] “, Also , we used 1 and $ metalcharacters to
confirm that there are no extra are characters at the beginning or end of the string .

Now , if the credit – card number is valid , then a web page is sent if part executinon , Thanking the
client completing registration from . But if the creadit-card number is invalid, the else part gets
executed, instructing the user to enter a valid creadit- card number.

5.6.2 Server – side include (SSI)

Dynamic Web pages greatly improves the look and feel of a web site. Dynmic web pages eincludes the
current date or time , rotating banners or advertise or advertisements, special offers or daily news
(newspaper) since they are all current informations. Clients receive new information on every visit and
thus they revisit the web site in the future . Thus. These dynamic web pages are generated mostely by
using SSI (Server – Side Includes, ).

Server – side Includes (SSi) are the commands embedded in a HTML documents to create dynmic
contents on web page. SSI commands (like ECHO and INCLUDE) creates the dynamic contents (like the
current time , web page hit counter i.e ., counting number of times a client requested the web page or
information that is stored in a database ) on a web pag. The SSi command EXEC ean ber used to run CGI
scripts and enmbed their output directly on a web page. A document containing SSi commands has
shtml extension (where s stands for server ). nThe shtml files are parsed by the server and it excutes the
commands and writes the output to client . it is advviable for the minimum use of server include
commands, as they decreases the performance of the the server.

Since all web does not . support SSI commands. They all are written as HTML comments.

5.22

5.7 INTRODUCATION TO USE OF XML IN WEB DESIGN

XML is a markup language developed by world wide web Consrtium’s (W3C’s ) XML working group in
1996. XML documents contains only data but not formatting instruction . XML, permits us to creat
markup for any type of information. That is in, XML , we create our own tags and syntax for those tags.

This extensibility enables us to create own new markup languages for mathematical formulas, music,
etc. Some XML-based markup language Intertion Language (for multimedia presentations , ).CML –
Chemical Markup Language (for Chemistry ) and XBRL – eXtensible Business Reporting Language (for
financial data exchange.)

XML document is highly portable. Processing XLM document requires a software called as XML parser or
XLM procer checks the XLM document’s syntax and process marked-up data. XML parsers can support
Document object Model (DOM) or simple AOL for XML (SAX). DOM-based parserts builds tree structure
containing XLM documents for tags, text, comments, etc. Even Internet Explorer 5.5. (IE 5.5) parser
(msxml) can parse and display XLM document.
From Microsoft’s point of view, we can use XML to create the following :

 An ordinary document.
 A structure record. (For example : An appointment record or purchase recode).
 An object with data and methods . (For example: The persistent from of a Java object or ActiveX
control).
 A data recod (For example : The resultset of a query)
 Metacountent about a web site. (For example. Channel Definition Format (CDF)).
 Graphical presention. (For example : An application’s user interface)
 XML schemens and types.

5.7.1 Creating XML Documents

A XML document ends with the. Xml filename extension. Viewing or b modifying an XML document
does not requires special software . Any editor that supports ASCII/Unicode charecters can open
XML documents to view and editor. An important feature of XML is that it is that is both human
readable and machine readable.

The following code is our first XML document that holds the purchasing records of several
customers;

Program ; purchase. Xml

<?xml version = “1.0”>

<purchase>

<title>

HAMEDSUFI presenting an XML document!

</title>

<date>

March 14, 2005

</date>

<custmore>

<name>

<first_name> Anees </first_name>

<last_name> Khan </last_name>

</name>
<onter>

<item>

<product> Video tape </product>

<price> $ 1.25 </price>

</item>

<order>

</customer>

<customer>

<name>

<first_name> Mukarram <first_name>

<last_name> Uddin </last_name>

</name>

<order>

<item>

<product> Gold Fish</product>

<price>$ 1.50</price>

</item>

<item>

<product> Angel fish</product>

<price> $ 1.75 </price>

</item>

</order>

</customer>

</purchase>

You might wonder that, XML provides you with a way of creating and structuring your data in a
manner that first that data.
XML document begins with XML processing instruction <?xml version = “1.0”>, which helps
Internet Explorer to know that this document is XML. Much like the <HTML> tag indicates an HTML
document. Placing space characters before XML declaration is an error.

Every XML document must contain exactly one root element which contains eery other XML
element In above program, purchase is the root element .

XML Element title, data contains text tht describes the purchase ‘s title, date of the document,
respectively . The other elements such as customer, name, order, item that contains other elements
are called as XML contains, Elements. Elements inside i.e. a container element first_name,

Last_name, product and price are called as child elements or children of that container elements .
XML elements and attributes names within XML elements can be of any length and may container
letters digits, underscore, hyphens and periods. However . XML element names must beging with
either a letter or an underscore Using either a space or a tab in an XML elements name or attributes
name is an error. XML element name and attributes names should be meaningful and in human
readable format , For example, use <purchase> instead of <pur>.

IE 5.5 places the symbols plus sign(+) and minus sign (-) to container elements in the output of the
above XML document. A minus sign display container elements child elements .Clicking tha minus
sign, hides container elements chikern and replaces the minus sign with a plus sign. Clicking the plus
sign again displays continer elements children the plus sign with a minus sign

5.7.2 XML Namespaces

XML document allows authors to create their own XML elements with their own names. But this can
result in naming collisions i.e., multiple different element can have the same in one XML document.

For example ,

<Subject> Math </Subject>

And

<subject> Multimedia and Web Design </Subject> uses XML element subject to markup a piece of
data . However , in the first case the subject is something oe studies in school , whereas in the
second case the subject is in the filed of engineering .

But XML, Namespaces provide a means fr us to prevent collisions by differentiating these two
subject elements using nams=espaces prefixes;

<School : subject> Math </school;subject>

And
<engineering ; subject> Multimedia and Web Design </engineering ; subject>

Both school and engineering are namespace prefixes.

XML namespace uses the keyword xmlns to create namespace prefixes and assign the
corresponding URI (Uniform Resource Identifier ) that uniquely identifies the name space . A URI is a
series of characters for differentiating names, for examples, the string

“Surepublication: textInfo” could be a URI for a namespace that contains elements and attributes
related to SURE publications.

The following program demonstrates namespace the differentiate two didtinct files;

Program : namespace.xml

<directory

Xmlns: = “Suerpublications : book: textInfo”

xmlIns: image = “Surepublications : book : imageinfo”>

<text ; file filename = “bo.xml”>

<text: description>

</text : file>

<image : file filename = “logo. Gif”>

<image ; description > Logo picture </image: description>

</image : file>

</directory>

In the above program , to get the file and description of the text of the book, we have prefixed with
the namespace text so, b it searches it in sure publications: book: text Info . And to get the file and
description of the image (logo) of the book , we prefixed with the namespace image. So , it searches
it in Sure publications book: image Info .

5.7.3 Valid and Well-Formed XML Documents.

An XML document is called as Valid XML document if there is a Document Type Definition (DTD ) OR
XML Schema associated with it and if the document complies with the DTD or XML schema.

An XML document is called as Well-Formed XML document if it contains one or more elements, and
if there is precisely one element (the root or document element) for which nethier the start tag the
end tag is inside any other element, and if all other tags nest within each other correctly , and if all
elements used the document must either be predefined in XML. DTD or XML schema.

5.7.4 XML Document Type Definitions (DDs) and XML Schemas

As ML documents can have many different structure , an application cannot tell whether particular
XML document is completer or missing data or order properly. So, this problem can be solved by
providing an extensible means of specifying XML document structure using the following two types
of documents;

(i) XML Document Type Definitions


(ii) XML Schemas

Applications can use DTDs or schemas to perform validity checks on XML documents.

5.7.4.1 XML Document Type Definitions

The DTD indicates the syntax of the XML elements for example, what elementrrs can be inside other
elements. The DTD follows the WBC syntax conventions, which means each element is specified
with <! ELEMENT>and the contents of an element are specified with # PDCDATA (Parsed Character
Data. ).

If we want to sure that our documents are valid (i.e, adhere to the syntax rules we set). Then we
need Document Type Definiton (DTD) or a schem. We can use the following two types of DTDs with
XML documents:

(a) Internal DTD


(b) External DTD
(a) Internal DTD

In an internal DTD, we enclose the DTD in a <!DOCTYPE> element, providing the name of the root
element of the document (which is PURCHASE here in this program ) in the <! DOCTYPE> element .

Potrebbero piacerti anche