Web Technology II · Unit 8
Database Operations
Exam-focused notes for Database Operations (Web Technology II, BIT301): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.
What this unit covers
- Database connection creation
- MySQLi object interface
- PHP Data Objects and PDO
- Database querying and SQL execution
- Data retrieval and display
- Data insertion into tables
- Data deletion from tables
- Result set handling
Data deletion from tables
Consider you have student records in a database table. Now create a PHP page with delete button action and a text field. The button should delete a record if it matches the name of the student entered in the text field. Use your own assumption for the database table. [5]
The page works against a database school holding one table of students. Nothing about the design is unusual: a surrogate key, the student name, and two descriptive columns. id name age address ------------------------ 1 Ram Sharma 20 Kathmandu 2 Sita Thapa ...
Full solved answer →PHP Data Objects and PDO
What is a PHP Data Object? How does MySQLi Object Interface work? Write a PHP program to read data elements from a database table and display in a page.[10]
PDO is a database access layer that gives PHP one uniform, object oriented interface over many database engines: MySQL and MariaDB, PostgreSQL, SQLite, SQL Server, Oracle and others. The engine is named only in the DSN, the connection string, so moving an a...
Full solved answer →Database connection creation
How can you create a database connection? Create a PHP form that includes text field, password field, radio button elements. Now write a function to insert the data in the fields into a database table.[10]
PHP does not talk to MySQL directly, it uses an extension. Two are current: MySQLi, which works with MySQL and MariaDB only, and PDO, which puts the same interface in front of a dozen database engines. Both open a connection from four pieces of information,...
Full solved answer →Database querying and SQL execution
How can you query a database in PHP? [5]
Querying a database from PHP always follows the same shape: open a connection to the server, hand it an SQL statement, and read back either a result set (for a SELECT) or a count of affected rows (for an INSERT, UPDATE or DELETE). Two extensions are current...
Full solved answer →Data retrieval and display
Write a PHP program to connect database and retrieve data from a table and display in a page. [5]
A database collegedb holding a table of students: The script opens the connection, runs a SELECT, and renders the rows into an HTML table. The query text here is fixed, so query() is enough; if the page later filters by something the visitor typed, the stat...
Full solved answer →Make Unit 8 stick
Practice BIT301 with flashcards & quizzes