Connecting a web project to a database is a core skill for any developer. In this blog, I’ll explain how to connect HTML, JavaScript, PHP, and Python projects with MySQL using localhost XAMPP, in a simple and practical way.
This guide is beginner-friendly and works perfectly for student projects, assignments, and local development.
What Is XAMPP?
XAMPP is a free local server package that includes:
-
Apache – Web server
-
MySQL (MariaDB) – Database
-
PHP – Server-side scripting
-
phpMyAdmin – Web-based database manager
Using XAMPP, we can run websites and databases locally (localhost) without buying hosting.
Step 1: Install and Start XAMPP
-
Download XAMPP from the official website
-
Install it
-
Open XAMPP Control Panel
-
Start:
-
✅ Apache
-
✅ MySQL
-
If both turn green, your local server is running.
Step 2: Create a MySQL Database (phpMyAdmin)
-
Open your browser
-
Go to:
-
Click New
-
Create a database, for example:
Example Table
Project Folder Structure (Important)
All PHP files must be inside:
Example project:
Step 3: Connect PHP with MySQL (XAMPP)
db.php (Database Connection)
save.php (Insert Data)
index.html (Frontend Form)
Run in browser:
Step 4: Using JavaScript (AJAX / Fetch API)
JavaScript cannot directly connect to MySQL.
It must send data to PHP or Python.
JavaScript (Fetch API)
✔ JavaScript → PHP → MySQL
❌ JavaScript → MySQL (not allowed)
Step 5: Connecting Python with MySQL (Localhost)
Python usually works separately from XAMPP, but connects to the same MySQL server.
Install MySQL Connector
Python Connection Example
Python Web App + MySQL (Flask Example)
If you want Python like PHP (web-based):
Run:
Common Mistakes (Very Important)
❌ Opening HTML file directly
✔ Always use:
❌ JavaScript connecting to MySQL
✔ Use PHP / Python as backend
❌ Wrong database name
✔ Match phpMyAdmin database exactly
❌ Apache or MySQL not started
✔ Start both from XAMPP Control Panel
Technology Flow Diagram (Simple)
When to Use What?
| Technology | Use Case |
|---|---|
| HTML | Frontend UI |
| JavaScript | Interactivity & AJAX |
| PHP | Simple backend with XAMPP |
| Python | ML, AI, APIs, Flask/Django |
| MySQL | Database |
Final Words
XAMPP is the best starting point for learning full-stack development. Once you understand this flow, you can easily move to live hosting, cloud servers, or Docker.
This setup is perfect for:


0 Comments