Chapter 6
Chapter 6
Database System Concepts - 7th Edition 9.2 ©Silberschatz, Korth and Sudarshan
Application Programs and User Interfaces
Database System Concepts - 7th Edition 9.3 ©Silberschatz, Korth and Sudarshan
Application Architecture Evolution
Database System Concepts - 7th Edition 9.4 ©Silberschatz, Korth and Sudarshan
Web Interface
Database System Concepts - 7th Edition 9.5 ©Silberschatz, Korth and Sudarshan
The World Wide Web
Database System Concepts - 7th Edition 9.6 ©Silberschatz, Korth and Sudarshan
Uniform Resources Locators
https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL
Database System Concepts - 7th Edition 9.7 ©Silberschatz, Korth and Sudarshan
Uniform Resources Locators
Scheme indicates the protocol that the browser must use to request the
resource.
• “http” indicates that the document is to be accessed using the Hyper
Text Transfer Protocol. “https” is the secured version of http.
Domain Name indicates which Web server is being requested.
Port indicates the technical "gate" used to access the resources on the
web server. It is usually omitted if the web server uses the standard ports
of the HTTP protocol.
Path to the file can be a physical file location on the Web server, and can
be an abstraction handled by Web servers without any physical reality.
?key1=value1&key2=value2 are extra parameters provided to the Web
server.
#SomewhereInTheDocument is an anchor to another part of the resource
itself
Database System Concepts - 7th Edition 9.8 ©Silberschatz, Korth and Sudarshan
HTML
Database System Concepts - 7th Edition 9.9 ©Silberschatz, Korth and Sudarshan
Example: test1.html
For more information, see https://devdocs.io/html/
head: information about the page and
how to process it
Database System Concepts - 7th Edition 9.10 ©Silberschatz, Korth and Sudarshan
Sample HTML Source Text
<html>
<body>
<table border>
<tr> <th>ID</th> <th>Name</th> <th>Department</th> </tr>
<tr> <td>00128</td> <td>Zhang</td> <td>Comp. Sci.</td> </tr>
….
</table>
<form action="PersonQuery" method=“get” >
Search for:
<select name="persontype">
<option value="student" selected>Student </option>
<option value="instructor"> Instructor </option>
</select> <br>
Name: <input type=text size=20 name="name">
<input type=submit value="submit">
</form>
</body> </html>
Database System Concepts - 7th Edition 9.11 ©Silberschatz, Korth and Sudarshan
Display of Sample HTML Source
Database System Concepts - 7th Edition 9.12 ©Silberschatz, Korth and Sudarshan
table row table header table data
submission type is
“get” means
appending form
data into URL in
attribute
~ name=value pair.
~ name of the
that will submit
parameter you
This is the destination file to
which the data is submitted
to. It is not available. (Its
implementation in servlet is
on Page 412 of the
textbook.)
Database System Concepts - 7th Edition 9.13 ©Silberschatz, Korth and Sudarshan
Client Side Scripting
Database System Concepts - 7th Edition 9.14 ©Silberschatz, Korth and Sudarshan
Javascript
Javascript very widely used
• Forms basis of new generation of Web applications (called Web 2.0
applications) offering rich user interfaces
Javascript functions can
• Check input for validity
• Modify the displayed Web page, by altering the underling document
object model (DOM) tree representation of the displayed HTML text
• Communicate with a Web server to fetch data and modify the current
page using fetched data, without needing to reload/refresh the page
Forms basis of AJAX (Asynchronous JavaScript and XML)
technology used widely in Web 2.0 applications
E.g. on selecting a country in a drop-down menu, the list of states
in that country is automatically populated in a linked drop-down
menu
Database System Concepts - 7th Edition 9.15 ©Silberschatz, Korth and Sudarshan
Javascript
Database System Concepts - 7th Edition 9.16 ©Silberschatz, Korth and Sudarshan
Document
Object Model
Not
implemented
yet
Database System Concepts - 7th Edition 9.17 ©Silberschatz, Korth and Sudarshan
PHP
PHP is a programming language. It can create, manipulate, and output
data. It runs on a web server. The output of a PHP code, which is a
text, is sent to a browser. The text could contain html.
Part of the remaining slides follow
PHP for Beginners by Dave Hollingworth on Udemy
https://www.udemy.com/course/php-for-beginners-/
Database System Concepts - 7th Edition 9.18 ©Silberschatz, Korth and Sudarshan
client/server request/response sequence
Basic level
Database System Concepts - 7th Edition 9.19 ©Silberschatz, Korth and Sudarshan
client/server request/response sequence
1. You enter http://server.com into your browser.
Dynamic Web page 2. Your browser consults DNS (domain name system)
to find the IP address of server.com
3. Your browser issue a request for the home page of
server.com
4. The request crosses the internet and arrives at the
server.com web sever
5. The web server, having received the request,
fetches web page from its disk.
6. With the home page now in memory, the web sever
notices that it is a file incorporating PHP scripting
and passes the page to the PHP interpreter.
7. The PHP interpreter executes the PHP code
8. Some of the PHP contains SQL statement, which
now PHP interpreter passes to MySQL database
engine.
9. The MySQL database returns the result of the
statements to the PHP interpreter.
10. The PHP interpreter returns the results of the
executed PHP code, along with the results from
MySQL database, to the web server.
11. The web server returns the page to the requesting
client, which displays it.
Database System Concepts - 7th Edition 9.20 ©Silberschatz, Korth and Sudarshan
Install PHP on MacOS and Windows
Mac
• Uninstall MySQL on Mac
• Install XAMPP on Mac
Windows
• Uninstall MySQL on Windows
Uninstall MySQL.
Remove the following three MySQL folders.
Database System Concepts - 7th Edition 9.21 ©Silberschatz, Korth and Sudarshan
MacOS: First, uninstall MySQL on Mac
1. open system settings to find MySQL 2. press uninstall
Database System Concepts - 7th Edition 9.22 ©Silberschatz, Korth and Sudarshan
MacOS: Then, install XAMPP
In order to develop code locally on my computer, I need to
stall a web server, a database server. XAMPP can install
and config all of these (Apache web server with php,
mariadb database, phpMyAdmin) for you all at once.
A replacement for MySQL. MySQL code
and data are 100% compatible with
MariaDB
www.apachefriends.org
Database System Concepts - 7th Edition 9.23 ©Silberschatz, Korth and Sudarshan
MacOS: Install of XAMPP
1. Double click the dmg file
4. Press next
Database System Concepts - 7th Edition 9.24 ©Silberschatz, Korth and Sudarshan
MacOS: Install of XAMPP
5. 6.
Database System Concepts - 7th Edition 9.25 ©Silberschatz, Korth and Sudarshan
MacOS: Install of XAMPP
9. Create a folder (which I called www, but it can be
any name and can be placed anywhere) to store the
files in the future.
10. Stop the “Apache Web server”, Press “Configure"
button, Open Conf File, Search for “DocumentRoot”
11. Replace the two
“/Applications/XAMPP/xamppfiles/htdocs” by the path
to the folder: /Users/jliu/teaching/database/www
12. Save the change. Press “OK”. Start “Apache web
server” again.
Database System Concepts - 7th Edition 9.26 ©Silberschatz, Korth and Sudarshan
Windows
Database System Concepts - 7th Edition 9.27 ©Silberschatz, Korth and Sudarshan
A simple PHP program: Hello World
1. The address of the web server install on my computer is local host. When web server
is running, it sits and waits for request for files. The requests normally come from web
browsers.
2. When you type the address of a web server into your web browser, it requests the site
from the web server. The web server receives the requests and sends the requested file
back.
3. When a php file on the server is requested, the web server first executes the php code,
then the results of executing that code are sent to the browser. (php runs on the web
server, not in the browser.)
opening php tag. No closing tag. See
database.php on Page 60
Database System Concepts - 7th Edition 9.28 ©Silberschatz, Korth and Sudarshan
Variables and function in PHP
# of seconds of one
day
~
concatenation
https://www.php.net/manual/en/
function.date.php
https://www.php.net/manual/en/l
anguage.constants.magic.php
Database System Concepts - 7th Edition 9.29 ©Silberschatz, Korth and Sudarshan
“foreach ... as” loop
Control flow in PHP
Database System Concepts - 7th Edition 9.30 ©Silberschatz, Korth and Sudarshan
“View Source” and “Inspect”
In Chrome, “View Source” shows the HTML that was delivered from
the web server to your browser.
In Chrome, Inspect elements is a developer tool to look at the state
of the DOM (Document Object Model) tree after the browser has
applied its error correction and after any Javascript have
manipulated the DOM.
Database System Concepts - 7th Edition 9.31 ©Silberschatz, Korth and Sudarshan
Recall
1. You enter http://server.com into your browser.
Dynamic Web page 2. Your browser consults DNS (domain name system)
to find the IP address of server.com
3. Your browser issue a request for the home page of
server.com
4. The request crosses the internet and arrives at the
server.com web sever
5. The web server, having received the request,
fetches web page from its disk.
6. With the home page now in memory, the web sever
notices that it is a file incorporating PHP scripting
and passes the page to the PHP interpreter.
7. The PHP interpreter executes the PHP code
8. Some of the PHP contains SQL statement, which
now PHP interpreter passes to MySQL database
engine.
9. The MySQL database returns the result of the
statements to the PHP interpreter.
10. The PHP interpreter returns the results of the
executed PHP code, along with the results from
MySQL database, to the web server.
11. The web server returns the page to the requesting
client, which displays it.
Database System Concepts - 7th Edition 9.32 ©Silberschatz, Korth and Sudarshan
PHP arrays
• Associative array
• Provides pairs of (key => value) elements
https://www.php.net/manual/en/language.types.array.php
Example: Output:
Mixed int and
string keys
Database System Concepts - 7th Edition 9.33 ©Silberschatz, Korth and Sudarshan
Associative arrays in PHP
Database System Concepts - 7th Edition 9.34 ©Silberschatz, Korth and Sudarshan
view source
In Google Chrome, right click the web page and choose “view page source”
Database System Concepts - 7th Edition 9.35 ©Silberschatz, Korth and Sudarshan
Associative arrays in PHP
Database System Concepts - 7th Edition 9.36 ©Silberschatz, Korth and Sudarshan
phpMyAdmin
Database System Concepts - 7th Edition 9.37 ©Silberschatz, Korth and Sudarshan
phpMyAdmin
1. Choose SQL tab to enter the query and then press go. (You can also
directly choose the Databases tab to create a database.)
Database System Concepts - 7th Edition 9.38 ©Silberschatz, Korth and Sudarshan
phpMyAdmin
2.Choose Databases tab. Click university 3. university database is chosen
Database System Concepts - 7th Edition 9.39 ©Silberschatz, Korth and Sudarshan
phpMyAdmin
4. Click import tab. Choose file DDL.sql (obtained from db-book.com). Press import.
5. Similary, import
smallRelationsInsertFile.sql or
largeRelationsInsertFile.sql
Database System Concepts - 7th Edition 9.40 ©Silberschatz, Korth and Sudarshan
phpMyAdmin
7. Result
Database System Concepts - 7th Edition 9.41 ©Silberschatz, Korth and Sudarshan
Create a new database and insert data
Click “server: localhost” from the last figure. Then choose “Databases” tab.
Enter “cms” (content management system) and then press “create”
Database System Concepts - 7th Edition 9.42 ©Silberschatz, Korth and Sudarshan
Create a database and insert data
Enter “article” for Table name and 4 for Number of columns. Then press
“create”
Database System Concepts - 7th Edition 9.43 ©Silberschatz, Korth and Sudarshan
Create a database and insert data
I auto increment
Database System Concepts - 7th Edition 9.44 ©Silberschatz, Korth and Sudarshan
Create a database and insert data
Choose “Insert”. Enter two records (I only showed one). Then press go.
Database System Concepts - 7th Edition 9.45 ©Silberschatz, Korth and Sudarshan
Create another user
Select Database: cms from the red box in the last figure. Choose
“Privileges” tab. Then click “Add user account”. Enter information. Then
press “go” in the bottom.
Database System Concepts - 7th Edition 9.46 ©Silberschatz, Korth and Sudarshan
Remark: To use MySQL/MariaDB in Python
output:
Database System Concepts - 7th Edition 9.47 ©Silberschatz, Korth and Sudarshan
index_firststep.php
2. Enter http://localhost/index_firststep.php in a browser
1. Place this file index_firststep.php in
the folder you created on Page 26.
Database System Concepts - 7th Edition 9.48 ©Silberschatz, Korth and Sudarshan
https://www.php.net/manual/en/mysqli.construct.php
• mysqli_connect — Open a new connection to the MySQL server
https://www.php.net/manual/en/mysqli.connect-error.php
• mysqli_connect_error — Returns a description of the last connection error
https://www.php.net/manual/en/mysqli.query.php
• mysqli_query — Performs a query on the database
https://www.php.net/manual/en/mysqli.constants.php#constant.mysqli-
assoc
• Predefined Constant MYSQLI_ASSOC : Fetch associative array. Columns are
returned into the array having the fieldname as the array index.
Database System Concepts - 7th Edition 9.49 ©Silberschatz, Korth and Sudarshan
Index_secondstep.php file
Database System Concepts - 7th Edition 9.50 ©Silberschatz, Korth and Sudarshan
Modify the database, the webpage changes
1. Modify the database
2. The webpage
changes accordingly.
Database System Concepts - 7th Edition 9.51 ©Silberschatz, Korth and Sudarshan
HTTP Request Methods
Recall: A client (browser) sends an HTTP request to the server; then
the server returns a response to the client.
The two most common HTTP request methods for browser to sent
user input are GET and POST.
The GET method is used to request data from a specified resource.
The query string (name/value pairs) is sent in the URL.
The POST method is used to send data to a server to create/update a
resource. No data in the URL. The web server bundles up all the user
input into an associative array named $_POST
Database System Concepts - 7th Edition 9.52 ©Silberschatz, Korth and Sudarshan
Passing data in the URL
https://www.php.net/reserved.variables.server
• $_SERVER is an array containing information such as headers, paths, and script
locations.
• Entry 'QUERY_STRING’ of $_SERVER is the query string (name/value pairs) which is
sent in the URL of a GET request.
• Entry ‘REQUEST_METHOD’ of $_SERVER tells which request method was used to
access the page; e.g. 'GET', 'HEAD', 'POST', 'PUT’.
https://www.php.net/manual/en/reserved.variables.get.php
• $_GET is an associative array passed to the current script via the URL parameters
(aka. query string).
on the server HTTP works as a request-response
protocol between a client and server.
Database System Concepts - 7th Edition 9.53 ©Silberschatz, Korth and Sudarshan
Index.php file
Database System Concepts - 7th Edition 9.54 ©Silberschatz, Korth and Sudarshan
article.php file
Only 1 record.
Fetch it as an
associative array
Database System Concepts - 7th Edition 9.55 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 9.56 ©Silberschatz, Korth and Sudarshan
Save data to database
1.Open
new_article.php
3. It shows
“Inserted record
with ID: 4”
Database System Concepts - 7th Edition 9.57 ©Silberschatz, Korth and Sudarshan
Save data to database
4.
5.
Database System Concepts - 7th Edition 9.58 ©Silberschatz, Korth and Sudarshan
A HTML form submits information via the HTTP POST method if the
form's method attribute is set to "POST".
https://www.php.net/manual/en/mysqli.insert-id.php
• mysqli_insert_id — Returns the value generated for an AUTO_INCREMENT column
by the last query
Database System Concepts - 7th Edition 9.59 ©Silberschatz, Korth and Sudarshan
~ skipped
Break code into pieces
Database System Concepts - 7th Edition 9.60 ©Silberschatz, Korth and Sudarshan
Part 2 of Project 2
1. Changed the type of ID in table student from varchar(5) to, say, varchar(15).
Database System Concepts - 7th Edition 9.61 ©Silberschatz, Korth and Sudarshan
Part 2 of Project 2
Database System Concepts - 7th Edition 9.62 ©Silberschatz, Korth and Sudarshan
Summary
Database System Concepts - 7th Edition 9.63 ©Silberschatz, Korth and Sudarshan