MySQL Interaction from PHP
1️⃣ Connecting to MySQL
Using MySQLi (Procedural)
Using MySQLi (Object-Oriented)
Using PDO (PHP Data Objects) — Recommended
2️⃣ Running Queries
Select Data
MySQLi Procedural
MySQLi Object-Oriented
PDO
3️⃣ Inserting Data
MySQLi Prepared Statement (Object-Oriented)
PDO Prepared Statement
4️⃣ Updating Data
MySQLi Prepared Statement
PDO Prepared Statement
5️⃣ Deleting Data
MySQLi Prepared Statement
PDO Prepared Statement
6️⃣ Closing Connection
-
MySQLi
-
PDO
Why Use Prepared Statements?
-
Prevents SQL Injection attacks by separating query logic and data.
-
Safer and more reliable for user input.