lOMoARcPSD| 23136115
DATABASE SYSTEMS PRACTICE EXAM
– MAFE204IU
Time: 90 minutes
Total Points: 100
SECTION A – THEORY QUESTIONS (5 pts each)
1. Describe the process of connecng a PHP le to a MySQL database, including server
selecon, error handling, and database selecon.
Answer: Use mysqli_connect() with server, username, password. Check with
mysqli_connect_errno(). Use mysqli_select_db() to choose database.
2. Explain the role of search.html and result.php in creang a search funcon for a web
app. How do they communicate?
Answer: search.html provides a form for input. result.php uses POST to get input,
performs SQL query, and shows results.
3. Create a simple ER diagram for a mini library system with Book, Author, and Borrower
enes.
Answer: Book(ISBN, Title), Author(ID, Name), Borrower(ID, Name). Relaonships:
BookAuthor (writes), Borrower-Book (borrows). PKs and FKs indicated.
4. What is SQL injecon? Give an example and suggest one method in PHP to prevent it.
Answer: SQL injecon is manipulang SQL with input. Example: ' OR 1=1 --. Prevent with
prepared statements or mysqli_real_escape_string().
5. Where should .php and .html les be stored for local deployment?
Answer: Store in C:/xampp/htdocs/. Access via hp://localhost/lename.php
6. What roles do Apache and MySQL play in a web database applicaon?
Answer: Apache handles HTTP requests and serves .php les. MySQL manages the
database. PHP connects them.
lOMoARcPSD| 23136115
SECTION B – PRACTICAL CODING (10 pts each)
7. Write a show.php le that retrieves data from the instructor table.
Answer:
<?php
$con = mysqli_connect("localhost", "root", "", "unidb"); $result
= mysqli_query($con, "SELECT * FROM instructor"); echo
"<table border='1'><tr><th>ID</th><th>Name</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>";
} echo
"</table>"; ?>
8. Create search.html with dropdown and text input.
Answer:
<html><body>
<form acon="result.php" method="post">
<select name="type">
<opon value="instructor">Instructor</opon>
<opon value="student">Student</opon>
</select>
Name: <input type="text" name="name">
<input type="submit" value="Search">
</form></body></html>
9. Write result.php to search based on input.
Answer:
<?php
$type = $_POST['type'];
$name = $_POST['name'];
$con = mysqli_connect("localhost", "root", "", "unidb");
$sql = "SELECT * FROM $type WHERE name LIKE '%$name%'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($result)) {
echo $row['name'] . "<br>";
}
?>
10. Write update.html and update.php to update salary.
lOMoARcPSD| 23136115
Answer (HTML):
<form acon="update.php" method="post">
ID: <input type="text" name="id"><br>
New Salary: <input type="text" name="salary"><br>
<input type="submit" value="Update">
</form>
Answer (PHP):
<?php
$id = $_POST['id'];
salary =
$_POST['salary'];
$con = mysqli_connect("localhost", "root", "", "unidb"); $sql =
"UPDATE instructor SET salary=$salary WHERE id='$id'";
mysqli_query($con, $sql); echo "Updated"; ?>
SECTION C – MINI-PROJECT CASE (15 pts each)
11. List the checklist for mini-project web app.
Answer: Complete ERD, database tables, MySQL implementaon, Apache cong, HTML
forms, PHP processing, PDF report, live demo.
12. Describe linking mproj.html to funcons.
Answer: Use <a href="show.html">Show</a>, etc. Users navigate through hyperlinks to
show/search/update. Each opens the corresponding page.

Preview text:

Instructor Student Name: