FAQ - Three tier architecture in asp.net - Asked By waseem kaleem on 27-May-11 01:22 PM

Can we develop website in three tier architectue in php?
Can we develop generic function in php?   
Peter Bromberg replied to waseem kaleem on 27-May-11 02:03 PM
Your post is confusing. In the title you say "in asp.net". Then in the body you say "PHP".
Which is it?

You can develop a three tier architecture in both ASP.NET and PHP. As of version 5, PHP supports classes.
Ravi S replied to waseem kaleem on 27-May-11 02:06 PM

3-tier application is a program which is organized into three major disjunctive tiers on layers. Here we can see that how these layers increase the reusability of codes.

These layers are described below.

1. Application layer or Business layer
2. Business layer
  a. Property layer(Sub layer of business layer)
3. data layer

Presentation Layer (UI) 
Presentation layer cotains pages like .aspx or windows form where data is presented to the user or input is taken from the user. 

Business Access Layer (BAL) or Business Logic Layer 
BAL contains business logic, validations or calculations related with the data, if needed. I will call it Business Access Layer in my demo. 

Data Access Layer (DAL) 
DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo application, I have taken a very simple example. I am assuming that I have to play with record of persons (FirstName, LastName, Age) and I will refer only these data through out this article. 

refer the links for examples



TSN ... replied to waseem kaleem on 27-May-11 11:44 PM

Three-Tier Architectures

This tutorial describes web database applications built around a three-tier architecture model, shown in Figure 1-1. At the base of an application is the database tier, consisting of the database management system that manages the database containing the data users create, delete, modify, and query. Built on top of the database tier is the complex middle tier, which contains most of the application logic and communicates data between the other tiers. On top is the client tier, usually web browser software that interacts with the application.

Figure 1-1. The three-tier architecture model of a web database application

The formality of describing most web database applications as three-tier architectures hides the reality that the applications must bring together different protocols and software. The majority of the material in this tutorial discusses the middle tier and the application logic that brings together the fundamentally different client and database tiers.

When we use the term "the Web," we mean three major, distinct standards and the tools based on these standards: the Hypertext Markup Language (HTML), the Hypertext Transfer Protocol (HTTP), and the TCP/IP networking protocol suite. HTML works well for structuring and presenting information using a web browser application. TCP/IP is an effective networking protocol that transfers data between applications over the Internet and has little impact on web database application developers. The problem in building web database applications is interfacing traditional database applications to the Web using HTTP. This is where the complex application logic is needed.

The Client Tier

The client tier in the three-tier architecture model is usually a web browser. Web browser software processes and displays HTML resources, issues HTTP requests for resources, and processes HTTP responses. As discussed earlier, there are significant advantages to using a web browser as the thin-client layer, including easy deployment and support on a wide range of platforms.

There are many browser products available, and each browser product has different features. The two most popular windowing-based browsers are Netscape and Internet Explorer. While we won't describe all the features of web browsers, they have a common basic set:

  • All web browsers are HTTP clients that send requests and display responses from web servers (usually in a graphical environment).

  • All browsers interpret pages marked up with HTML when rendering a page; that is, they present the headings, images, hypertext links, and so on to the user.

  • Some browsers display images, play movies and sounds, and render other types of objects.

  • Many browsers can run JavaScript that is embedded in HTML pages. JavaScript is used, for example, to validate a <form> or change how a page is presented based on user actions.

  • Selected web browsers can run components developed in the Java or ActiveX programming languages. These components often provide additional animation, tools that can't be implemented in HTML, or other, more complex features.

  • Several browsers can apply Cascading Style Sheets (CSS) to HTML pages to control the presentation of HTML elements.

There are subtle-and sometimes not so subtle-differences between the capabilities different browsers have in rendering an HTML page. Lynx, for example, is a text-only browser and doesn't display images or run JavaScript. MultiWeb is a browser that renders the text on a page as sound-the spoken word-providing web access for the vision-impaired. Many subtle but annoying differences are in the support for CSS and the features of the latest HTML standard, HTML 4.

Web browsers are the most obvious example of a user agent, a software client that requests resources from a web server. Other user agents include web spiders-automated software that crawls the Web and retrieves web pages-and proxy caches, software systems that retrieve and locally store web pages on behalf of many other user agents.

The Middle Tier

In most three-tier web database systems, the majority of the application logic is in the middle tier. The client tier presents data to and collects data from the user; the database tier stores and retrieves the data. The middle tier serves most of the remaining roles that bring together the other tiers: it drives the structure and content of the data displayed to the user, and it processes input from the user as it is formed into queries on the database to read or write data. It also adds state management to the HTTP protocol. The middle-tier application logic integrates the Web with the database management system.

In the application framework used in this tutorial, the components of the middle tier are a web server, a web scripting language, and the scripting language engine. A web server processes HTTP requests and formulates responses. In the case of web database applications, these requests are often for programs that interact with an underlying database management system. The web server we use throughout this tutorial is the Apache Software Foundation's Apache HTTP server, the open source web server used by more than 60% of Internet connected computers.[2]

From The Netcraft Web Server Survey, http://www.netcraft.com/survey/ (April 2001).

We use the PHP scripting language as our middle-tier scripting language. PHP is an open source project of the Apache Software Foundation and, not surprisingly, it is the most popular Apache HTTP server add-on module, with around 40% of the Apache HTTP servers having PHP capabilities.[3] PHP is particularly suited to web database applications because of its integration tools for the Web and database environments. In particular, the flexibility of embedding scripts in HTML pages permits easy integration with the client tier. The database-tier integration support is also excellent, with more than 15 libraries available to interact with almost all popular database management systems.

Web Servers

Web servers are often referred to as HTTP servers. The term "HTTP server" is a good summary of their function: their basic task is to listen for HTTP requests on a network, receive HTTP requests made by user agents (usually web browsers), serve the requests, and return HTTP responses that contain the requested resources.

There are essentially two types of request made to a web server: the first asks for a file-often a static HTML web page or an image-to be returned, and the second asks for a program to be run and its output to be returned to the user agent. Simple requests for files are further discussed in Appendix B.

Requests for web scripts that access a database are examples of HTTP requests that require a server to run a program. With the software used in this tutorial, the HTTP requests are for PHP script resources, which require that the PHP Zend engine be run, a script retrieved and processed, and the script output captured.

hope this helps you...

waseem kaleem replied to waseem kaleem on 28-May-11 12:13 AM

I am very very sory.Topic is Three tier architecture in php.can you provide some example of three tier architecture in php?
as In asp.net, we develop generic class of data access layer by Dictionnary or Hashtable.How can we develop such class in php? 

Thank you very very much for quick response. 

Jitendra Faye replied to waseem kaleem on 28-May-11 12:39 AM

Three tier architecture  includes following layer

Presentation Layer

This layer will mainly consist of user interface of the website i.e. the visible part of a website.

2. Business Logic Layer

This layer acts as a mediator between Presentation layer and Data Access layer. This layer will have the business logic implementations and it transfers the data between the two layers.

3. Data Access Layer

This layer deals with the database and database related codings. We write stored procedures, queries in this layer.


You can refer this for more details



Jitendra Faye replied to waseem kaleem on 28-May-11 01:03 AM

For that you have to follow these steps-

step1.  Add one class file in your website, using add new item, name - DataLayer.cs

step2: define one function in that class file, to get data.

like this-

public static class DataLayer


Public static DataSet getdata(string query)


SqlConnection con = new SqlConnection("constring");

SqlDataAdapter da;

string mySQL = query;

da = new SqlDataAdapter(mySQL, con);


DataSet ds = new DataSet();


Return ds;



note - this function should be public otherwise you can't access this function from other class.

step3.  Add one more class file in your website, using add new item, name - BusinessLayer.cs

step4: define this function in thit class file, to call getdata method of DataLayer class.

like this-

public class BusinessLayer


Public DataSet getEmpdata(string query)


DataSet ds = new DataSet();

ds= DataLayer.getdata(query)

Return ds;



step5: Now call this function from other place(UI/Presentation layer) ,

like this-

private void button2_Click(object sender, EventArgs e)


  GridView.DataSource=BusinessLayer.getEmpdata("Select * from Emptable");

follow these steps and let me know.

Anoop S replied to waseem kaleem on 28-May-11 01:18 AM
PHP is a scripting language and does not follow a 3-tier architecture. You use this to process logic and interact with the database and then usually send HTML back to the browser.