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%

20. MySQL Integration & Functions

Lesson 17 of 29 in the free PHP Programming notes on Siksha Sarovar, written by Rohit Jangra.

PHP with MySQL

PHP and MySQL are widely used together to create dynamic, database-driven web applications such as login systems, registration forms, e-commerce websites, etc.

What is MySQL?

MySQL is an open-source relational database management system (RDBMS) used to store and manage data in tables.

Features of MySQL

  • Open source and free
  • Fast and reliable
  • Uses SQL (Structured Query Language)
  • Works well with PHP
  • Supports large databases
Exam Definition: MySQL is a relational database that stores data in the form of tables using SQL.

---

Integration of PHP with MySQL

PHP communicates with MySQL using MySQLi or PDO extensions.

Steps for PHP–MySQL Integration

  1. Create database
  2. Create table
  3. Connect PHP with MySQL
  4. Perform database operations (CRUD)

Database Connection (MySQLi)

$conn = mysqli_connect("localhost", "root", "", "testdb");

if(!$conn){
   die("Connection Failed");
}
Exam Tip: mysqli_connect() is used to connect PHP with MySQL.

---

MySQL Functions in PHP

PHP provides built-in functions to work with MySQL databases.

Common MySQLi Functions

FunctionPurpose
mysqli_connect()Connect database
mysqli_query()Execute query
mysqli_fetch_assoc()Fetch row as array
mysqli_fetch_array()Fetch row
mysqli_num_rows()Count rows
mysqli_close()Close connection

Example: Fetch Data

$result = mysqli_query($conn, "SELECT * FROM users");

while($row = mysqli_fetch_assoc($result)){
   echo $row['name'];
}