Developing php web application

web application in php

web application in php

Developing PHP Web Application
With the DB Visual ARCHITECT (DB-VA) you can develop quality PHP Web Application much faster, better and cheaper.
All DB-VA generated code, configuration file and persistent layer library are deployable to Apache Server with PHP. DB-VA
generates all PHP code for accessing database. You do not need to write SQL to insert, query, update or delete the record. All
code you need to program is plain PHP code (e.g.;). In this chapter we will use a simple “School
System” application to show you how to generate PHP code, configure your web application, creating, querying, updating and
deleting objects. Again you do not need to write a single SQL statement for all the above operations.
The architecture of PHP Web Application with DB-VA Persistent Layer
In this chapter:
· Introduction
· Generate code in Apache Http Server
· Creating Object and Saving to Database
· Querying Object from Database
· Updating Object and Saving to Database
· Deleting Object in Database
You will develop a School System.
The School System provides the following functions:
· Create course by teacher
· Enroll course for student
· Cancel course by teacher
· Register for user
· Modify the personal information
· View the Course information (number of students enrolled and teacher information of the course)
Required Software:
· DB Visual ARCHITECT 3.0 Java or Professional Edition (
· PHP 4.4.2 or above (
· Apache Http Server 2.20 or above (
· MySQL Server 4.1 or above (

Generate Code in Apache Http Server
You can generate the PHP code in Apache Http Server’s htdocs folder or setup a virtual host to execution. The following step
will teach you to directly generate PHP code to htdocs folder.
1. Create a new PHP Project in Eclipse. You must select the Directory in Installed Apache Http Server’s htdocs.
Figure 3.3 – Create a new project
2. Generate the PHP to the schoolsystem Project in DB-VA. From menu bar, select Tools > Object-Relational
Mapping (ORM) > Generate Code…to open the Database Code Generation dialog box.

Fill in code generation information.
Code tab:
For Generate, select Code and Database to generate code and create database option.
For Language, select PHP language.
For Output Path, select the C:\Apache\htdocs\schoolsystem. The project created in Eclipse.
For Persistent API, select Factory Class.

  • Database Code Generation dialog
    Database tab:
    You can reference Chapter 1 to select export the database schema and configure the default database of jdbc
  1. Click OK to the PHP code is generated to C:\Apache\htdocs\schoolsystem.
  2. Refresh the SchoolSystem Project in Eclipse.
    To refresh the project
    Programmer’s Guide for PHP Chapter 3 – Developer PHP Web Application
  3. The PHP Code is generated. You can start Apache Http Server and try to access the SchoolSystem project.
    For example:
    You can develop your PHP Web Application in Eclipse now.
    Creating Object and Saving to Database
    The school system provides a separate register page for teacher and student to enter their information. The register method of
    teacher and student method is the same, so we will demonstrate how to create the teacher and save to database.

  4. Create “teacherreg.html” for teacher to input their personal information and register to the system. The submit
    information will be processed by userlogin.php to add new user.

Teacher Register

Teacher Register

User ID :
Teacher Full Name :
Password :
Email :


Source File : SchoolSystem\teacherreg.html
Teacher Register page
Programmer’s Guide for PHP – Developing PHP Web Application

  1. Create the user to create the teacher record in system and provide the unique user ID.
    · The createUser.php can identify to create teacher or student by hidden field in “teacherreg.html”

· The createuser.php method to create teacher and student. It gets the information from the “teacherreg.html”
by $_POST.
$userType = $_POST[“userType”];
$id = $_POST[“loginID”];
$name = $_POST[“name”];
$pwd = $_POST[“password”];
Source File : SchoolSystem\createuser.php
· Create Teacher instance from TeacherFactory.
if ($userType == “teacher”){
$user = TeacherFactory::createTeacher();
$user->email = $_POST[“email”];
} else {
$curtime = time();
$user = StudentFactory::createStudent();
$user->enrolmentDate = date(“Ymd”);
Source File : SchoolSystem\createuser.php
· Call save() method of Teacher instance to create the record in database. Add Teacher id to session to
represent the user has login to the system.
$_SESSION[‘userID’] = $id;
Source File : SchoolSystem\createuser.php
3. When you submit the form the Teacher object will be added to the database. The new user id is added to the Session.
If user attribute exists in session, the user is login to the system.
Figure 3.8 – The record is added
Programmer’s Guide for PHP Chapter – Developer PHP Web Application

Querying Object from Database
You can retrieve the record in database as object. For example, you need to create the login function for the School System.
You will require the user to input the User ID and password to login, the system retrieve the User object from the user id and
compare the password to validate the user.
1. Create the Login page (login.php). It submits the form to the userlogin.php. If user has login, it will redirect the user to
student page or teacher page depends on the user type.

Login Page


Login ID :
Password :

getForeignObject(), ‘Student’)){
header(“Location: studentpage.php”);
} elseif (is_a($user->getForeignObject(), ‘Teacher’)){
header(“Location: teacherpage.php”);

Source File : SchoolSystem\login.php
Figure 3.9 – Login Page
Programmer’s Guide for PHP Chapter 3 – Developing PHP Web Application
2. Use User ID to call loadUserByORMID() method to retrieve the User object in userlogin.php and compare the
$user = UserFactory::loadUserByORMID($id);
if (!is_null($user) && $user->password == $pwd){
$_SESSION[‘userID’] = $id;
if (is_a($user->getForeignObject(), ‘Student’)){
header(“Location: studentpage.php”);
} elseif (is_a($user->getForeignObject(), ‘Teacher’)){
header(“Location: teacherpage.php”);
Source File : SchoolSystem\userlogin.php
Updating Object and Saving to Database
You can modify the teacher information and update the record in database. You get the User id from the session and get the
user instance from database to set the new values for the User object, finally call save() method to update the record in
1. Click modify personal information link on the Teacher Page
– Teacher Page
2. Modify the information in modifyUser.php. Get the User id from session and get the user instance from database to
set the information to field and allow the user to modify the information, finally submit the form to the

Modify Information

Modify User Information

getForeignObject(), ‘Teacher’)){
Programmer’s Guide for PHP Chapter 3 – Developer PHP Web Application

Name : id=”studentName” value=”name; ?>”>
Password : id=”password” value=”password; ?>”>
Email : value=”email; ?>”>

Source File : SchoolSystem\modifyUser.php
Figure 3.11 – Modify Information
3. The processModifyUser.php get the modified information from the submitted form and set to the User object and call
save() method to update the record in database. It is similar to create user.
getForeignObject(), ‘Teacher’)){
$email = $_POST[’email’];
$user->email = $email;
$user->name = $name;
$user->password = $pwd;
header(“Location: login.php”);
Source File : SchoolSystem\processModifyUser.php
Programmer’s Guide for PHP – Developing PHP Web Application

Deleting Object in Database
Teacher can create course for students for registration and they can cancel the course in the system. They only need to click
cancel hyperlink of the course then the course information will be deleted in the database and all its relationship with registered
students will be removed.
1. Teacher can create the course by selecting Create Course hyperlink in teacher page. Fill in Course name and
Description to create Course.
– Create Course
2. Student can register the course in the student page.
– Student Page
3. The teacher can view how many students have registered his course and he can cancel the course.
– Teacher Page
4. Click Cancel of a Course then it will pass the course id to the processDeleteCourse.php. The processDeleteCourse.php
contains which uses the Course ID to retrieve to Course Object.
$courseID = $_GET[‘courseID’];
$course = CourseFactory::loadCourseByORMID($courseID);

Source File : SchoolSystem\processDeleteCourse.php
5. Call deleteAndDissociate() method to delete the course object and remove the relationships of student and teacher
with the course.
Source File : SchoolSystem\processDeleteCourse.php


myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , , , , , , , , ,
Posted in html and css, javascript and jquery, php

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Follow Tutorial on
June 2012
    Jul »
Follow me on Twitter
Blog Stats
  • 78,798 hits
%d bloggers like this: