Aim
To use phpMyAdmin to import data, review data and structure, run SQL statements, and create users with privileges — and to reproduce the same workflow programmatically with PDO.
Theory
phpMyAdmin is a browser-based administration GUI for MySQL/MariaDB — itself written in PHP — that ships with XAMPP at http://localhost/phpmyadmin. Everything it does is ordinary SQL fired at the server; the tabs just organise it:
- Import runs a
.sqldump file (schema plusINSERTs) — the standard way to move a database between machines. - Structure lists a table's columns, types, keys and indexes (the GUI face of
DESCRIBE), while Browse shows the rows (SELECT *). - SQL is a free-form box for arbitrary statements.
- User accounts manages MySQL's privilege system:
CREATE USER 'lab_user'@'localhost' IDENTIFIED BY '...'makes an account,GRANT SELECT, INSERT, UPDATE, DELETE ON college_lab.* TO ...scopes what it may touch, andFLUSH PRIVILEGESreloads the grant tables. Applications should connect as such a least-privilege user, never asroot.
PDO (PHP Data Objects) is the programmatic equivalent the snippet uses: one uniform API where only the DSN chooses the engine — mysql:host=localhost;dbname=college_lab in the lab, sqlite::memory: in the compiler — so the same PHP code demonstrates the import → browse → structure workflow anywhere.
Requirements
- XAMPP/WAMP with Apache and MySQL running; phpMyAdmin (bundled with XAMPP)
- PHP 8.x with PDO (pdo_mysql in the lab; pdo_sqlite for the compiler run)
- Code editor (VS Code); browser
Procedure
- Start Apache and MySQL from the XAMPP Control Panel and open
http://localhost/phpmyadmin. - Create a database
college_lab; use Import to load a.sqldump; open Structure and Browse on the resulting table; run aSELECTunder SQL; finally add an account under User accounts and grant it privileges oncollege_lab. - Save the snippet as
p23_phpmyadmin.phpinC:\xampp\htdocs\wbplab; to run it against MySQL change the DSN tomysql:host=localhost;dbname=college_lab(userroot, empty password on stock XAMPP). - Open
http://localhost/wbplab/p23_phpmyadmin.php, or runphp p23_phpmyadmin.php— the compiler uses PDO with in-memory SQLite, so the identical PHP performs the same operations, with the MySQL-only user/privilege statements kept as reference comments at the end.
Explanation of the Code
new PDO("sqlite::memory:")opens a throwaway database that lives only for this run; settingATTR_ERRMODEtoERRMODE_EXCEPTIONmakes every SQL error throw instead of failing silently.- Step 1 mirrors Structure:
CREATE TABLE studentswithINTEGER PRIMARY KEY AUTOINCREMENT— SQLite's spelling of MySQL'sAUTO_INCREMENT. - Step 2 mirrors Import:
$importRowsplays the dump file; one preparedINSERTwith?placeholders is executed per row, then the row count is echoed. - Step 3 mirrors Browse/SQL:
query()->fetchAll(PDO::FETCH_ASSOC)fetches every row, printed as#id | name | email. - Step 4 mirrors Structure again:
PRAGMA table_info(students)is SQLite'sDESCRIBE, yielding each column's name, type and primary-key flag. - Step 5 keeps
CREATE USER/GRANT/FLUSH PRIVILEGESas comments — SQLite has no user system, so they are reference-only.
Expected Output
The run prints Imported 3 rows into 'students'., then a Browse (SELECT *): block with #1 | Riya | riya@example.com, #2 | Aman | aman@example.com and #3 | Rohit Kumar | rohit@example.com, then Structure of 'students': listing - id (INTEGER) [PRIMARY KEY], - name (VARCHAR(100)) and - email (VARCHAR(120)). The commented privilege statements produce no output. In phpMyAdmin itself the same actions appear as GUI results: imported rows under Browse, the column list under Structure, and the new account under User accounts.
🎯 Viva Questions
- What is phpMyAdmin? A web-based GUI for administering MySQL/MariaDB, written in PHP — every action it performs is ordinary SQL.
- What does the Import tab accept? A
.sqldump (or CSV) whose statements are executed to recreate schema and data. - Structure vs Browse? Structure shows columns, types, keys and indexes; Browse shows the actual rows.
- Why create a dedicated MySQL user instead of using
root? Least privilege — a compromised application can then only touch what wasGRANTed to it. - What does
FLUSH PRIVILEGESdo? Reloads MySQL's grant tables so privilege changes take effect immediately. - Why can this snippet run unchanged on SQLite and MySQL? PDO gives one API for many engines; only the DSN string selects the driver.
CO Mapping
CO1, CO2