Learning Database Through Developing Database Web
Learning Database Through Developing Database Web
net/publication/332346954
CITATIONS READS
2 5,190
1 author:
Ching-Yu Huang
Kean University
59 PUBLICATIONS 538 CITATIONS
SEE PROFILE
All content following this page was uploaded by Ching-Yu Huang on 18 May 2019.
II. DATABASE CURRICULUM 3) The following SQL statement shows the unique
Relational DB [8] are often adopted for teaching purposes department for any staff who has name contains the
because it still accounts for the majority of the DB job market; letter “e”.
thus, they will be the focus of the curriculum. The proposed SELECT distinct dept from Staff WHERE name like
DB curriculum is based on 40 total hours - 32 hours of total '%e%';
lesson time (13 weeks and 2.5 hours per week) and 4 exams, 4) The following SQL statement shows the names of all
with 2 hours allocated for each, including reviewing the staff who are female and have a salary >= 40000.
answers. Students should have at least a basic level of SELECT name FROM Staff WHERE sex='F' and salary
programming knowledge with a good foundation in variables, >= 40000;
loops, logic conditions, if statements, arrays, and functions. 5) The following SQL statement shows the names and
The curriculum will build on this prerequisite knowledge by salaries of all staff that work at IT department, with the
focusing on basic DB knowledge and its application. output sorted from high to low (in salary).
Theoretical concepts such as relational calculus, and SELECT name, salary FROM Staff WHERE dept=’IT’
advanced topics such as triggers, transactions, concurrency ORDER BY salary DESC;
control, query Processing & optimization, DBA, and data TABLE I: STAFF TABLE
mining are not covered. The assignments include 2 sid name dept sex salary ext
homework assignments and one web DB application project, 101 Mary IT F 45000 121
with two phases. 102 Smith HR M 37000 NULL
103 Tony IT M 38000 115
Instructors should prepare several tables with records and 104 Sarah PJ F 35000 311
export the tables into SQL files for students to download. 105 Mark IT M 45000 153
This way, students can import the tables into their local 106 Alice HR F 39000 433
MySQL server and work on the same tables and dataset as 107 Ben IT F NULL NULL
that of the instructors. Consequently, everyone should obtain
the same results when doing exercises with the same SQL C. Web DB Application
statements. If students have any difficulties, instructors can In the 3rd week, students should learn how to display the
quickly help the students. Students should do more exercises data from the DB on the browser after learning the basic
on basic SQL operations, and should not be limited to the SELECT statements. This should be done twofold: first, the
examples shown in this paper, as this is not intended to be a instructor should quickly cover basic web design and how to
textbook. The following subsections detail the weekly take input and pass the values to PHP programs on the
curriculum. Apache web server. Then, students should learn how to use
A. Introduction of DB PHP to retrieve the data from the DB using the input values.
The first week of lessons should include the following The main goal of this paper is to focus on learning the basic
topics: class policy, the course schedule, an overview of the DB queries and integrating the DB and Web. This means
DB curriculum, basic DB concepts, and the role of DB in only basic web programming is required to show how the
modern software systems. The fundamental knowledge of the web and DB work together. Students should take web
client-server model and 3-tier architecture should be covered. programming courses for learning how to design better web
Instructors should also help students install the XAMPP pages and more aesthetic GUI. Project 1 should be given in
package, and make sure the MySQL and Apache web servers the 3rd week and should be due at the end of the 7th week. The
can be run successfully. details of the project are described in section 2.4.
1) Input on web page (browser)
B. BASIC SQL — Select, Where, Sorting
Hypertext Markup Language (HTML) is a markup
The 2nd week should cover basic concepts of tables, rows,
language to create web pages and web applications using tags
columns, and data types. This week focus on the SQL
<>. Many HTML tags have attributes that can modify
SELECT command and its syntax, with AS, LIKE,
elements, specify tags’ values, or perform specific actions.
DISTINCT, ORDER BY, AND, OR, NOT, and WHERE
The browser will interpret the tags and attributes, with
clauses. Students should be able to select specific records and
specific syntax, that will take input and display results. The
columns with simple and compound conditions. In addition,
HTML file should have the *.html extension and should
one should cover how to sort the output. Homework 1 should
begin with an <HTML> tag and end with an </HTML> tag.
be given in the 2nd week, and due at the end of the 6th week. It
Fig. 1 shows the HTML source code of a simple web page
should mainly focus on the SELECT queries. As a result of
that allows a user to enter input. The web page is shown in
this week’s curriculum, students should be able to write the
Fig. 2. Most HTML tags require end tags </> to match the
following SQL statements based on Table I, a sample table of
begin tag <>.
staff members at a company.
The message written between <TITLE> and </TITLE>
1) The following SQL statement shows all columns, for all
will be displayed as the title of the web page. The <BR> tag
staff.
creates a new single line break. The <input> tag specifies an
SELECT * FROM Staff;
input field where the user can enter data. <input> elements
2) The following SQL statement shows the salary and
are used within a <form> element to declare input controls
department for any staff named Mary.
which allow users to input data [9]. An input field can vary in
SELECT salary, dept FROM Staff WHERE name='Mary';
many ways, depending on the type attribute. The first
242
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
<INPUT> tag allows users to enter text, and the 2nd values of the corresponding name in the array (note that the $
<INPUT> tag is a submit type which will ask the browser to sign is used to indicate variables in PHP). For example, the
pass the values of <INPUT> tags, which are placed between following statement will assign the ‘keyword’ value of
<FORM> and </FORM> tags, to the program on the web <INPUT> tag in Fig. 1 to a PHP variable $value.
server. More information about HTML tags can be $value=$_GET['keyword'];
referenced at w3schools.com [10]. 4) Access MySQL using PHP
PHP has built-in functions to work with MySQL DB [12].
<HTML> The basic steps are as follow: 1. Establish a connection to the
<TITLE>Test</TITLE>
DB on a server with a valid login and password. 2. Send the
Web DB application: search department
<BR> query string. 3. Receive the results and place them in a PHP
<FORM action='check.php'> array. 4. Check the number of rows in the array. 5. Fetch all
Department: the records in the result array. 6. Free the result array and
<INPUT type='text' name='keyword' method=’GET’> close the connection. A sample program that follows this
<INPUT type='submit' value='Check'> procedure is shown in Fig. 3. The program connects to the
</FORM>
“test” database on the “localhost” server using the login
</HTML>
“tester” and password “1234”.
Fig. 1. The HTML source code of test.html.
If the DB connection fails, the program can use
mysqli_connect_error() to show the error message returned
from the DB; the program should terminate immediately and
display the error message. It will be a waste of the web
server’s resources if the login fails but the program continues
to run the rest of the statements.
As shown in the following PHP statement, a variable $sql
Fig. 2. The display on the browser from the HTML code shown in Fig. 1. stores the query string which selects the names and salaries
from the Staff table with condition dept='$value' (as assigned
2) Common gateway interface (CGI) in section 2.3.3).
A browser uses the CGI protocol to send the information to
a web server [11]. When the input values and other $sql= "SELECT name, salary FROM Staff where dept='$value'";
information shown on the browser are passed to the web
Please note that if the attribute is not a numeric type, the
server using the <FORM> tag, the browser also tells the web
PHP variable $value should be surrounded with single quotes
server to call the specific program defined in the action
for logic comparisons, and numeric values should not be
attribute of the <FORM> tag. For example, the PHP program
wrapped with single quotes for comparison. For example, to
check.php, which is defined inside the <FORM> tag in Fig. 1,
compare the salary column with the PHP variable, the correct
is called with the specific input. In order for this to work, the
comparison statement is salary=$value (to see if they are
program should be able to be executed directly by the OS
equal).
where the web server is running. Most of the CGI programs
The function mysqli_query() will send the query string to
are nowadays written in scripting languages because it is
the DB through the variable $conn. If the query is
easier to maintain. When the web server receives a message
successfully executed by the DB server, the returned results
from the browser, it will trigger the OS to call the language
are saved into the 2-D array $result. The function
interpreter to run the program.
mysqli_num_rows() returns the number of records stored in
There are two methods can be defined in the <FORM> to
the array. The function mysqli_fetch_assoc() will fetch a
pass the information from the browser to the web server –
record each time from the 2-D array and the record is saved to
GET and POST. The GET method will show the message
a 1-D array $row. The while loop will read every record in
string (name/value pairs) that is sent in the URL. Many
the 2-D array. The values of name and salary can be retrieved
search functions are implemented in the GET method so
from the 1-D array $row using the table column name
people can change keyword values in the URL. This will
“name” and “salary” as the keys. The results are displayed on
allow other programs to call the URL directly and obtain the
the browser using the <TABLE> tag and its related tags:
results. The POST method delivers a message in the HTTP
table row tag <TR>, table header tag <TH>, and table
message body, which is not visible from the URL. If the
data/cell tag <TD>.
message contains confidential information, such as a
Fig. 4 shows the results of a search with the keyword “HR”,
password or other information that should not be visible, it is
displayed in a table with 2 columns (name and salary) and 3
better to use the POST method.
rows. If the search does not yield any results, a warning
3) Web CGI programming using PHP message should be displayed so users know what happened.
The PHP program that the programmer wishes to call Fig. 5 shows the results if no record is found (i.e. if the search
should be written between the strings “<?php” and “?>”. For keyword is “XY”). For the 3-tier architecture commonly used
more PHP reference materials, tutorials for PHP can be found with web DB applications, bugs and problems might arise at
at w3schools.com [11]. Once the CGI program is called, it front-end, middle-end, or back-end. Therefore, it is important
will receive all the <input> tags’ names and values. In PHP, to keep users informed with meaningful messages about the
special arrays $_POST[] and $_GET[] are used to get the running status.
243
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
Fig. 3. PHP source code receives the input department value from the
browser and displays all staff names and salaries if the input department is
found in the DB.
Fig. 7. Display all the users and their columns from the DB.
Fig. 4. The results displayed on the browser when the input department is
“HR”. The “keyword” and its associated input value “HR” are displayed in Fig. 8. Login page.
the URL.
3) If the login ID and password match the records in the
database, the program should show the user’s IP and
other information, as shown in Fig. 9.
Fig. 6. The PHP program should show error messages if “keyword” is not E. SQL — Constraints; Creating Tables and Temporary
used, or if there are no input values passed through GET method. Tables; Alter and DROP
Students should learn how to create simple tables in this
If the PHP program check.php is run without using the
week as well as how to use constraints - datatype, primary
GET method with “keyword” and an input value, the
key, foreign key, auto increment, NOT NULL, default values,
program should terminate immediately and display an error
and possible range. Please note that it is very important to
message “No keyword is entered!”, as shown in Fig. 6. This
educate students on the impact of the data size. One extra
way, the web server will not waste any resources, as
byte of a column could result in an additional 1GB if there are
aforementioned. Since the web application can be accessed
1 billion records. Therefore, students should properly choose
by many people, it can be costly if preventative measures are
the data types; i.e. picking between char and varchar types, or
not taken. It is very important to teach students how to protect
picking between ints and strings.
the servers in the client-server architecture.
1) The following SQL statement details how to create a
The ALTER command can change the table structure; for
table named “Test” with 2 columns (id, name), where id
instance, it can add or remove a column, or change the
is of int type and name is of varchar type. Note that id
datatype and constraints. The DROP command will remove
will be set as the primary key and the value will
the entire table or any object from the DB. The commands
auto-increment.
CREATE, ALTER, and DROP are called Data Definition
CREATE TABLE Test (id int primary key auto_increment,
Languages (DDL) because their effects can be seen at the
name varchar(50));
structure level.
2) The auto_increment rule will let DBMS automatically
D. QUIZ 1 and Project 1 increment the value of the “id” column. The value is
244
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
245
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
SQL query. See the output in Fig. 11 below. id, in the “User” table. Vendor_id is also a foreign key
$sql="SELECT COUNT(sex) AS ct FROM Staff WHERE that references the primary key id in the “Vendor” table.
sex='F'"; Both the User and Vendor tables should be provided by
the instructor.
2) 2.8.2 Implement a function to search for products, as
shown in Fig. 12. The keyword should be pattern
Fig. 11. Result of 2.7.2. matched against the product name and description. If no
product is found, a proper message should be displayed.
After the name is changed, the following PHP statement
can use the meaningful key “ct” to retreive the value returned
from the DB.
Fig. 12. A user can enter a keyword to pattern match products by name or
$myCt=$row['ct']; description in the Student’s “Products” table.
3) The following SQL statement shows the maximum
salary of IT department. 3) Create an add product page, as shown in Fig. 13. The
SELECT MAX(salary) FROM Staff where dept = 'IT'; program should require that all data input fields not be
4) The following SQL statement shows the number of empty and for the numeric fields to not be negative (as
people that have an extension number. An instructor well as within a reasonable price range). The sell_price
should discuss how to use IS and IS NOT to find or must also be greater than the cost. These errors should be
exclude the NULL values. caught at the front-end, by JavaScript, to reduce the web
SELECT count(ext) FROM Staff; server’s load. If the same product already exists in the
The statement can also be written as: table, an error message should be displayed. If there are
SELECT COUNT(SID) FROM Staff WHERE ext IS NOT any errors about the data, the record should not be
NULL. inserted into the DB. The vendor id and name should be
5) The following SQL statement shows how to use the retrieved from the Vendor table and only the name
MAX, COUNT, SUM and AVG functions; remember should be displayed in the dropdown list on the web
that they are impacted by the presence of NULL values. page.
SELECT COUNT(salary), SUM(salary), AVG(salary),
MAX(salary) from Staff;
6) The following SQL statement shows the logic operations
AND and OR with NULL values. Please note that TRUE
is represented by 1 and FALSE is represented by 0 in
MySQL.
SELECT 1=1, 'a'='b', 1 AND 0, 1 OR 0, 1 AND NULL, 1 Fig. 13. An example implementation of 2.8.3.
OR NULL, NULL AND NULL, NULL OR NULL;
7) The following SQL statement will create a view vTest 4) Create an update product page, as shown in Fig. 14. The
that is not updatable. columns highlighted in yellow are not updatable. The
CREATE VIEW vTest AS SELECT dept, count(*) ct FROM Add Product checking rules (outlined in 2.8.3) should be
Staff GROUP BY dept; applied to the 4 updatable columns. Staff members
should be able to update multiple records at once. This
H. Midterm and Assignments
means that the instructor should teach students how to
The 75-minute midterm exam should cover topics from pass and receive <INPUT> in an array format, though
week 1 to 7. Instructor should also review the answers CGI. The following shows how one can use HTML to
following the exam so students know and understand the pass the product_id in an array format with the value 3
mistakes they made. Assignments Homework 1 and Project 1 and in hidden type.
should have been due in the end of the 6th and 7th week, <input type='hidden' name='product_id[]' value='3'>
respectively. The instructor should provide general feedback The following PHP code shows how to calculate the
for the students, so they know how to improve for the future. number of products passed from the browser, and how to
Homework 2 and Project 2 should be given to the students receive the product_id in an array format.
this week, and they are should be due in the 12th and 14th for($i=0;$i<count($_POST['product_id']);$i++) {
week, respectively. Homework 2 mainly covers SQL joins $product_id[$i]=$_POST['product_id'][$i];
and stored routines. }
Project 2 focuses on the integrating the learning in a
practical environment, with the following requirements I. SQL — Group by, Having, Insert, Update, Delete,
(2.8.1 to 2.8.4). The “search product” function should be Subquery, and in
available to anyone without login. For a user whole role is This week should cover how to group datasets using
“Staff”, they should be able to “Add” and “Update” product GROUP BY, add new records using INSERT, change data
pages. content using UPDATE, and remove a record using DELTE.
1) Create a “Product” table (id, name, description, From experience, grouping is one of the most challenging
sell_price, cost, quantity, user_id, vendor_id) where topics in SQL. The commands – SELECT, INSERT,
user_id is a foreign key that references the primary key, UPDATE, DELETE are called Data Manipulation Language
246
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
(DML), since their effects can be seen on the data level. (outer query). DBMS will need to execute the inner
query first to get the results for the outer query to use.
The following SQL statement uses subqueries to find the
person’s name who has the maximum salary in “IT”
department. The result is shown in Fig. 17, based on the
data in Table 1.
SELECT name, salary FROM Staff WHERE
salary=(SELECT MAX(salary) FROM Staff WHERE
dept='IT');
Fig. 14. An implementation of 2.8.4.
247
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
privileges from which hosts), and REVOKE, which can from the requirements, students should also learn how to
remove the privileges. The following SQL statement convert E-R diagrams to schema diagrams.
gives the SELECT privilege on the Staff table in the Test
O. Normalization and Physical Design
database to a user named ‘tester’, who can access the DB
from any host (%). For normalization, the instructor should cover traditional
GRANT SELECT ON Test.Staff to tester@% with grant decomposition, functional dependency, loss-less join, and 1st,
option; 2nd and 3rd normal forms. The Boyce–Codd normal form can
2) Web page authentication (e.g. login). This often be optional. Students should be able to break a big table into
requires the DB designer to store user login and several smaller tables and set the primary keys and foreign
password information in a table, for example, the “User” keys to link the smaller tables together.
table in the class project. The login will use the POST Physical designs include creating the following objects in
method to pass the login and password to the middle-end the DB: project database instances, user accounts with proper
program, which will verify with the data in the DB. The privileges, stored routines, and tables based on the schema
password should be encrypted by SHA256, or a better diagrams with the necessary columns to be indexed.
hash function. The password should not be readable Instructors should also teach how to estimate physical disk
directly select from the table. For example, Fig. 7 is a sizes for all the tables and recommend the partition size that
poor implementation of the password. will store the database files. It is also important to show
3) DB web page authorization through role control. students how to check where the database files are located on
Another way to improve web DB application security is the server. For example, the following SQL statement shows
to use roles to control who can access what web pages or the data folder for MySQL:
functions. The role can be a numeric level or a string, i.e. SHOW VARIABLES LIKE 'datadir';
“staff”, “student” shown in Fig. 7. The search function Physical design should not only cover database design, but
shown in Fig. 12 can be accessed by anyone, but the add should also include application design. Since project 2 is due
product page shown in Fig. 13 and update product page at the end of 14th week, the instructor should give overall
shown in Fig. 14 should be only accessed by “staff”. feedback about students’ projects and homework, especially
4) Using cookies and sessions to control when the web how the implementation relates to physical design – data type
page should expire. Authentication cookies are the most and validation, data flow between the 3-tier architecture, the
common method used by web servers to know whether relationship between tables, and date storage locations on the
the user is logged in or not, and which account they are DB server.
logged in with [13]. P. Final Exam
L. QUIZ 2 and Project 2 The exam should have two components – a take-home
The 60-minute Quiz 2 should cover materials from week 9 database design and in-class individual written exam. The
to 11, and the answers should be reviewed. Instructors should take-home is a teamwork assignment that requires a team to
use this week to check the status of project 2 and help have 5-8 students and design a mini database application.
students improve their web DB programming skills. Each team is given two forms – one for registration and one
for a report. The samples are shown in Fig. 19 and 20,
M. Planing and Requiremens respectively. Each team should have 4 different roles –
It is better to discuss DB planning and requirements after business staff, system engineer, database designer, and
students have completed their first web DB application software developer.
assignment, which will be discussed in section 3. This way, The business staff should write several business rules
they already have hands-on experience and know about the based on the two forms. The following are examples based on
DB features, function, and GUI firsthand and understand the the two forms:
importance of these requirements. In order to mimic the real 1) The registration should take 4 data fields.
world, instructors could have a group take-home exam after 2) The product information should not be shown in the
students learn all the basic SQL queries and let students play URL when they are passed to backend.
different roles (system engineer, database designer, software 3) The Graphic User Interface is based on the browser.
developer, and business staff) to plan a design for a 4) The ID should be automatically assigned by the system.
mini-online store and write the requirements. This way, The system engineer should write the detailed
students will have the opportunity to brainstorm together and requirements based on the business rules and the forms.
work as a team. Teamwork is very critical in web DB The database designer should draw the E-R diagram,
applications. create table statements, and perform any tasks related the
database.
N. Logic Design and E-R Model
The software developer should write the detailed code for
Traditional DB textbooks often introduce logic design and both front-end and back-end. The code should include the
the E-R model early in the course. However, from teaching following:
experiences, many students won’t be able to fully understand 1) HTML code to get user input and button to submit the
the real meaning of data modeling before they have any input to the webserver.
hands-on experience with DB. Therefore, this paper proposes 2) PHP code to validate the input data ranges before
to move the logic design and E-R model to later parts of the sending them to the database server.
curriculum. In addition to learning how to model the data
248
International Journal of Information and Education Technology, Vol. 9, No. 4, April 2019
3) PHP code to send the query to the database for inserting proposal is to focus on hands-on experience. Students will
and retrieving records. need to write a two-phase and 3-tier comprehensive project
4) PHP code to display the results returned from the that integrates the web browser, web server, and database
database on the browser. management system. Several software programs were
The in-class exam should include all topics covered in the proposed to help students quickly complete the project.
semester, and be weighted 30% for topics covered before
midterm and 70% after the midterm. REFERENCES
[1] C. Coronel and S. Morris, Database Systems: Design, Implementation,
& Management, 13th Edition, 2018.
[2] P. DuBois, MySQL, 5 Edition, Addison-Wesley Professional, April 12,
2013.
[3] L. Ullman, PHP for the Web: Visual QuickStart Guide, 5th Edition,
Peachpit Press, July 25, 2016.
[4] A. Peicevic, Apache HTTP Server Introduction, 2nd Edition,
CreateSpace Independent Publishing Platform, February 9, 2017.
[5] L. Welling and L. Thomson, PHP and MySQL Web Development, 5th
Fig. 19. The form to register a product.
Edition, Addison-Wesley Professional, September 30, 2016.
[6] XAMPP Apache + MariaDB + PHP + Perl. (2018). Apache Friends.
[Online]. Available: https://www.apachefriends.org/
[7] M. Delisle, Mastering phpMyAdmin 3.4 for Effective MySQL
Management, Packt Publishing, February 7, 2012.
[8] J. Eckstein and B. R. Schultz, Introductory Relational Database
Design for Business, with Microsoft Access, Wiley, January 16, 2018.
[9] G. Gupta, Mastering HTML5 Forms, Packt Publishing, November 22,
2013.
Fig. 20. The report to list the products with id, name and price. [10] PHP 5 Tutorial. (2018). [Online]. Available:
https://www.w3schools.com/php/
[11] M. Wright, How To Setup A Linux Web Server, CreateSpace
III. STUDENT LEARNING OUTCOME (SLO) Independent Publishing Platform, January 16, 2014.
[12] L. Ullman, PHP and MySQL for Dynamic Web Sites, 5th Edition,
Upon completion of this course, the student will be able to: Peachpit Press, November 13, 2017.
1) Explain and write basic SQL statements using the [13] J. LeBlanc and T. Messerschmidt, Identity and Data Security for Web
Development: Best Practices, O'Reilly Media, June 20, 2016.
SELECT, INSERT, UPDATE, DELETE commands.
2) Explain and write basic SQL statements to create and Ching-Yu Huang is an assistant professor of the
drop tables, views, and stored routines. School of Computer Science at Kean University,
Union, New Jersey, USA since September 2014. Dr.
3) Explain and write SQL statements to join multiple tables Huang received a Ph.D. in computer & information
with conditions, and group and sort the results. science from New Jersey Institute of Technology,
4) Design and build web database applications with Newark, New Jersey, USA.
authentication to retrieve, display, and update data using Prior to joining Kean University, Dr. Huang had
more than 16 years of experience in the industry and
the PHP language. academics in software development and R&D in bioinformatics. His research
5) Explain and demonstrate the normalization concepts and focuses SNP genotype calling and cluster detection; image processing and
process. pattern recognition, especially in microarray and fingerprint; geotagged
images and location information reconstruction; database application
development; data processing automation; E-learning, educational
multimedia, methodology, and online tools for secondary schools and
IV. CONCLUSIONS colleges. Dr. Huang has more than 40 publications in journals and
conferences and more than 20 presentations in workshops and invited
This paper proposes a fundamental curriculum for an lectures.
undergraduate database course. The main goal of this
249