January 31st, 2007
Design of the Database Schema In this section we will create the database schema of the application. The application’s data (tables and indices) will be stored in a separate database (shop). Generally all the schema objects related to an application should be stored in a separate database/table space. It helps in easy management of related database objects. For example, to back up the data of the shopping cart application, the database administrator has to back up only one database (shop). Database Tables The following tables will be created in the shop database: . UserProfile . BookShop . MusicShop . Transaction . Session The UserProfile table contains user information: Column Name Description Fname First name of the user Lname Last name of the user UserId Unique user id Password Encrypted password of the user Address Street address City City Country Country ZipCode Zip code Gender Male/Female Age User’s age Emailed User’s e-mail address PhoneNumber Phone number of the user CardNo User’s credit card number ExpiryDate Expiry date of the credit card CardType User’s credit card type Master/Visa AccountBalance Balance in the user’s account The BookShop table contains the description of available book titles: Column Name Description Itemno Unique identifier for the book Itemtype Book type Title Title of the book Page 547
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services
Posted in php4 | No Comments »
January 31st, 2007
a scripting solution is preferred over servlets and CGI programs. . PHP provides APIs for accessing a large set of databases, and supports features like persistent database connections, and sessions. These features will be heavily used in the middle tier. Page 546
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services
Posted in php4 | No Comments »
January 31st, 2007
Choosing Software The requirements of the application call for the application to be web-based, with a WML front-end. The application will require a back-end database to store user profiles, user transactions, and the list of music/book titles available at the site. The application will also have a middle tier (the web server plus scripts which are executed by the server), to process the application requests sent from the browser. The browser will send WAP (Wireless Access Protocol) requests to the WAP gateway, which in turn will forward the request to the middle tier using HTTP. The middle tier will get the data from the back-end database, do some processing on the data, and send the reply back to the WAP gateway, which in turn will send the data back to the client browser using the WAP protocol: Import ant A WAP gateway is software that acts as a bridge between a network that supports WAP protocol and Internet Protocol (IP) network. Alternatives for the Back-End Database The back-end database stores the following data: . Information about registered users . Book and music titles available at the site . Record of transactions carried out by users We have two alternatives for storing the above listed information: . Flat files . Relational databases like Oracle, MySQL, or Sybase Flat files are ruled out, because that would lead to implementing lots of functionality, like designing the layout so that the data can be manipulated later, and designing a simple interface for accessing the data from files. This functionality is already available in relational databases. We have chosen MySQL as our back-end database. The reasons for this include: . MySQL is an open source relational database, so it has a cost advantage over other commercial databases . MySQL is highly scalable and easy to administer . MySQL supports client APIs for a large set of programming languages (like Perl, C, and PHP), so it gives more choice of programming languages for implementing the middle tier Alternatives for the Middle Tier The middle tier will generate WML pages dynamically, using the data available in the back-end database. For example, to display the book titles available at the site, the middle tier will get the list of books from the back-end database, and will generate a WML page containing the list of books. The following are the alternatives for implementing the middle tier: . Common Gateway Interface (CGI) programs written in Perl/C. These programs can access the back-end database using the database’s language APIs. . Servlets, written in Java. Servlets can access the back-end database using Java’s SQL APIs and the database’s JDBC driver. JDBC drivers are available for almost all databases. . Server-side scripting language like PHP, JavaServer Pages (JSP), and Active Server Pages (ASP). These languages support APIs for accessing almost all relational databases. PHP is chosen for implementing the middle tier for the following reasons: . PHP is available on a large set of platforms (Linux, UNIX, and Windows NT) and a variety of web servers (Apache and IIS). Therefore, we get a choice of platform and web server for hosting the middle tier. . Performance is one of the implicit requirements for any web-based application, so Page 545
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check professional servlet hosting services
Posted in php4 | No Comments »
January 31st, 2007
End User Interaction Let’s look at the sequence of actions performed by typical users who visit the web site for shopping. New users coming to the site for the first time register themselves. Existing users authenticate themselves by providing their user id and password. After authentication is successful, the user, having browsed the music/book titles, adds the items to their cart. Additionally, they can view the list of items in their cart. The user might want to change the quantities of the items or delete the items selected earlier. After the user is sure that they want to buy all the items in their cart, they check out. Checking out is the confirmation from the user that they want to buy all the items in the cart. After the user has checked out, all the items in the user’s cart are entered in the database, and these items are shipped to the address of the user, given at the time of registration. After checking out, the user can continue shopping or can decide to log out. Users can also just browse the music and book titles available in the shopping site, without purchasing any items. Sometimes users are interested in viewing the current status of their account, and the status of items (for example whether they have been shipped or not) purchased by them earlier. The flow chart below describes the interaction of the user with the shopping cart application: Page 544
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services
Posted in php4 | No Comments »
January 31st, 2007
Requirement Analysis The first step in developing any application is to interview the user base to generate a list of features they would want in the application. This is an important input for defining the capabilities of the application. To keep the application simple, let’s assume that after interviewing the end users and customers, the following requirements were generated: . Users should be able to use the application from any mobile device supporting WML 1.1 and later. . Mobile devices need not support cookies, so the application should not use cookies. . The application should be usable from mobile devices. The application should take into account the small display size of these devices. . WML devices have a small memory footprint, so the browser cannot handle large WML pages. The size of the WML page that is returned to the device from the application must always be less than 1400 bytes. . The user transactions should be secure. That is, some basic authentication mechanism will be built into the application to prevent unauthorized persons from making transactions on a user’s behalf. . Users should be able to buy books and music albums from the site. . Users should be able to view a complete list of available books and music albums. . Users should be able to search for books by author and/or title. . Users should be able to search for music albums by artist and/or title. . Users should be able to search the entire database for keywords. . Users should be able to add items to their cart, and decide later whether they would like to buy the selected items. . Users should be able to change the quantities of items, or delete items from their cart. . After the user has checked out, all the items in the user’s cart should be shipped to the user. . Users should be able to view the status of items they have ordered. . The middle tier of the application should be scalable. That is, it should be possible to run multiple instances of the middle tier. In this chapter we will concentrate only on the end user requirements. In real-life, there would be another interface for the site administrators. This interface will allow them to view the transactions done on a particular day, and change the status of the items purchased by users. Page 543
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
Posted in php4 | No Comments »
January 31st, 2007
Chapter 16: A WAP Case Study Overview In this case study, we will develop a web-based shopping cart application for mobile devices using PHP. This application will allow users to access the shopping site from their mobile devices (mainly phones). Most of the cell phones available in the market today have a built in Wireless Markup Language (WML) browser. Users can browse different WML sites (for example, http://mobile.yahoo.com/home/), using the browser. In developing this application, we will go through the complete life cycle of software development. We will go through the following steps: . Identifying requirements . Choosing the right products and programming language for implementing the application . Designing the application . Implementing the design Page 542
Hint: If you are looking for high quality webhost to host and run your jsp application check Vision web hosting jsp services
Posted in php4 | No Comments »
January 30th, 2007
Summary In this chapter, we looked at multi-tier development as a way to develop web sites and applications. The whole idea around multi-tier development is to abstract the data (content), logic, and presentation layers to minimize the interaction between layers. When developing multi-tier applications, the focus should be on design and not on coding. Scalability and performance are fundamentally tied to the way you design and architect your application. The use of OOP and abstraction classes is the key to a successful multi-tiered architecture. We explored several alternatives for the data layer plain files, relational database, XML, and hybrid models. It is important to make sure that the data layer is isolated from the other layers using abstraction classes and APIs, so that it is possible to change the entire data layer without changing the programs using it. We explored the logic layer and the presentation layer, and we also looked into a common HTML based multi-tiered architecture, and a brand new approach using XML. Page 541
Hint: This post is supported by Gama web hosting php services
Posted in php4 | No Comments »
January 30th, 2007
that create graphical bars. If we do not have that functionality in the HTML class then we would have to create it. However, there might be other applications using graphical bars that will be favored by this code that they can later reuse the functions. As we can see, no change at all is needed in the logic layer. Presentation and logic are therefore independent. Case 2: Prevent the User from Voting Multiple Times This will imply a change to the logic. We can use cookies to prevent users for voting twice in the same poll. Advanced users can delete the cookies but we can live with that. Once this is decided, we just add the use of cookies and the controls to the logic layer of our application. These changes will not impact on the content or presentation layers. Case 3: A Flash Version The design team strikes again: they now want to present the whole application using nice Flash animations with sound, graphics, and dancing bears. Then we can just create a Flash class that will have the same interface as the HTML class and implement each method of the HTML class using PHP Flash functions. We do not have to change anything else there, but we have a Flash polls application. See Chapter 25 for examples of PHP’s Flash functions. Page 540
Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Sandzak jsp web hosting provider
Posted in php4 | No Comments »
January 30th, 2007
Operation Description getOptions($pollid) Given a pollid returns an array of optionIds for the given poll getOptionName($optionid) Given an optionId returns the name of the option getOptionVotes($optionid) Given an optionId returns the number of votes for that option addVote($optionid) Increments the number of votes of the given option addOption($pollid,$name) Adds an option to a poll removePoll($pollid) Deletes a poll and its options removeOption($optionid) Removes an option from a poll setCurrent($pollid) Sets the given poll as the current poll We can encapsulate all these functions in a Poll_Data class, which uses a DB object to access the database. If we change the database from MySQL to PostgreSQL we just instantiate a PostgreSQL DB object and the Poll_Data class will work without modifications. The Logic Layer We can identify two different logic modules in the logic layer. Firstly, an administration module where polls can be created, options added and removed, the current poll can be selected, and so on. This can be implemented as simple HTML forms using the presentation layer to draw the forms and the data manipulation layer to operate with the data model. Finally, we need an application module where the user will see the actual poll, vote, and then see the poll result. We do not take care of a user voting more than once in this simplified application. So we can create a Poll_Admin class with all the administrative functions and forms to display in a browser and a Poll_Application class with the functionality to show the poll, process the vote, and show the results. The Presentation Layer In the presentation layer we’ll build an HTML class to generate forms, to display the form, to create tables, and so on. This will be a highly generic class that will grow a lot as we create new applications requiring new presentation features. The data presentation component will have methods to display the poll form, to show the results, and to create forms. This class will be a client to the HTML class: the idea is that no HTML code at all will be present in the data presentation class (only calls to the HTML class are used). The Classic Multi-Tiered Architecture Let’s take a look at what happens if we design and create our poll application using this architecture. First, we can see here that we have a strong separation between the content layer, the logic layer, and the presentation layer. We also achieved independence of the database using the DB abstraction class and independence of the presentation language using the HTML class. Let’s see what happens if we have to modify the application. Case 1: The Poll Result Display Changes We used a table showing the options, the number of votes, and the results. The designers decide they now want to display a graphical representation of the percentage of votes in each option. Using this architecture, we just modify the data presentation layer to use functions in the HTML class Page 539
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services
Posted in php4 | No Comments »
January 30th, 2007
Designing the Poll Application We will now see a small example illustrating all the different layers and how to abstract them. We will work with our sample polls application that has polls and a current poll. Each poll has options, and when the user votes, the result of the poll is shown. Designing the Data Model We will use a database for storage so we are going to use a relational model for this application. The tables will have the following structure: polls pollid INTEGER(4) question VARCHAR(80) poll_options pollid INTEGER(4) optionid INTEGER(4) optname VARCHAR(80) votes INTEGER(4) The following script will create these tables: CREATE TABLE polls( pollid INTEGER(4) NOT NULL AUTO_INCREMENT, question VARCHAR(80), PRIMARY KEY(pollid)); CREATE TABLE poll_options( pollid INTEGER(4) NOT NULL, optionid INTEGER(4) NOT NULL AUTO_INCREMENT, optname VARCHAR(80), votes INTEGER(4), PRIMARY KEY(optionid)); CREATE TABLE current_poll( pollid INTEGER(4)); The Content Layer We’ll build the access component for a MySQL database. Here we do not cover the creation of the class since we don’t want to create a working example in this chapter, just the skeleton. We must implement all the operations to our data model in the data manipulation component: Operation Description createPoll($question) Creates a poll returning a pollid getCurrentPoll() Returns the pollid of the current poll Page 538
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services
Posted in php4 | No Comments »