Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Practical 23: phpMyAdmin Operations (Import, Structure, SQL, Users/Privileges)

Lesson 30 of 35 in the free Web Based Programming Lab notes on Siksha Sarovar, written by Rohit Jangra.

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 .sql dump file (schema plus INSERTs) — 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, and FLUSH PRIVILEGES reloads the grant tables. Applications should connect as such a least-privilege user, never as root.

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

  1. Start Apache and MySQL from the XAMPP Control Panel and open http://localhost/phpmyadmin.
  2. Create a database college_lab; use Import to load a .sql dump; open Structure and Browse on the resulting table; run a SELECT under SQL; finally add an account under User accounts and grant it privileges on college_lab.
  3. Save the snippet as p23_phpmyadmin.php in C:\xampp\htdocs\wbplab; to run it against MySQL change the DSN to mysql:host=localhost;dbname=college_lab (user root, empty password on stock XAMPP).
  4. Open http://localhost/wbplab/p23_phpmyadmin.php, or run php 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; setting ATTR_ERRMODE to ERRMODE_EXCEPTION makes every SQL error throw instead of failing silently.
  • Step 1 mirrors Structure: CREATE TABLE students with INTEGER PRIMARY KEY AUTOINCREMENT — SQLite's spelling of MySQL's AUTO_INCREMENT.
  • Step 2 mirrors Import: $importRows plays the dump file; one prepared INSERT with ? 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's DESCRIBE, yielding each column's name, type and primary-key flag.
  • Step 5 keeps CREATE USER / GRANT / FLUSH PRIVILEGES as 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

  1. What is phpMyAdmin? A web-based GUI for administering MySQL/MariaDB, written in PHP — every action it performs is ordinary SQL.
  2. What does the Import tab accept? A .sql dump (or CSV) whose statements are executed to recreate schema and data.
  3. Structure vs Browse? Structure shows columns, types, keys and indexes; Browse shows the actual rows.
  4. Why create a dedicated MySQL user instead of using root? Least privilege — a compromised application can then only touch what was GRANTed to it.
  5. What does FLUSH PRIVILEGES do? Reloads MySQL's grant tables so privilege changes take effect immediately.
  6. 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