
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 connecng a PHP le to a MySQL database, including server 
selecon, error handling, and database selecon. 
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 creang a search funcon 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 
enes. 
Answer: Book(ISBN, Title), Author(ID, Name), Borrower(ID, Name). Relaonships: 
BookAuthor (writes), Borrower-Book (borrows). PKs and FKs indicated. 
4. What is SQL injecon? Give an example and suggest one method in PHP to prevent it. 
Answer: SQL injecon is manipulang 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 hp://localhost/lename.php 
6. What roles do Apache and MySQL play in a web database applicaon? 
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 acon="result.php" method="post"> 
<select name="type"> 
<opon value="instructor">Instructor</opon> 
<opon value="student">Student</opon> 
</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 acon="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 implementaon, Apache cong, HTML 
forms, PHP processing, PDF report, live demo. 
12. Describe linking mproj.html to funcons. 
Answer: Use <a href="show.html">Show</a>, etc. Users navigate through hyperlinks to 
show/search/update. Each opens the corresponding page. 
                            Bấm  Tải xuống để xem toàn bộ.
                        
                                                    
                                                                            Preview text:
Instructor Student Name: