SlideShare a Scribd company logo
Open Source Technology
Dr.S Jeyalaksshmi
Associate Professor
Dept. BCA & IT
VISTAS
2
MySQL with PHP
Introduction to MySQL with PHP
• A database is your best choice for storing data in your web
application, and the MySQL database server has always been
the most popular choice among PHP developers.
• MySQL uses the SQL (Structured Query Language)
programming language to work with the data, and PHP
interacts with MySQL by simply passing SQL code through a set
of MySQL functions to the MySQL server, which then returns a
result that PHP can interpret.
3
Creating table in SQL
• CREATE TABLE employee
( eid int NOT NULL AUTO_INCREMENT,
name varchar(45) NOT NULL,
occupation varchar(35) NOT NULL,
age int NOT NULL, PRIMARY KEY (id) );
4
How to Create a Database?
• A database is defined as an organized collection of data
that makes the data easy to access, manage and modify.
Generally, databases use SQL (Structured Query Language)
for data manipulation.
5
To create a database:
1. Open XAMPP Control Panel and start the Apache server
and MySQL service.
6
STEP 2:
In your browser , type localhost in the address bar, and then on
the XAMPP dashboard, click on the Phpmyadmin tab.
http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/
7
STEP 3:
Into the phpmyadmin section, click on new to create a new
database. And name your database “db1”.
8
STEP 4:
Now, create a table named “db1” and create columns as
shown below, which you will use on the registration page.
9
10
11
12
1. <?php
2. $con=mysqli_connect('localhost','root','','db1'); database name
3. $check_data=mysqli_query($con,"select * from details");
4. $check=mysqli_num_rows($check_data);
5. if($check_data){ table name
6. while($row_data=mysqli_fetch_array($check_data)){
7. echo("ID:".$row_data['ID']."<br>");
8. echo("NAME:".$row_data['SNAME']."<br>");
9. echo("AGE:".$row_data['AGE']."<br>");
10. } server name
11. } username
12. else{
13. echo ("No data found");
14. }
15. ?>
13
14
How to Edit and Delete Data From the Database?
15
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $pass
word);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
16
if(! $conn )
{
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($conn);
17
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
18
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
echo “Connected successfully”;
mysqli_close($conn);
19
Structured Query Language (SQL) is made up of two sub-
languages:
• SQL Data Manipulation Language (DML)
SELECT statements perform queries INSERT, UPDATE,
DELETE statements modify the instance of a table
• SQL Data Definition Language (DDL)
CREATE, DROP statements modify the database schema
GRANT, REVOKE statements enforce the security model
20
Find the last names and hire dates of
employees who make more than $100000.
select LastName, HireDate
from Employee
where Salary > 100000
21

More Related Content

Similar to MySQL with PHP (20)

PDF
Php summary
Michelle Darling
 
PPTX
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
PPTX
MySql:Basics
DataminingTools Inc
 
PPTX
MySQL Basics
mysql content
 
PPTX
Making MySQL Agile-ish
Dave Stokes
 
PDF
Php 2
tnngo2
 
PPT
PHP - Getting good with MySQL part II
Firdaus Adib
 
PPTX
MySQL Introduction
mysql content
 
PPTX
MySql:Introduction
DataminingTools Inc
 
PPT
PHP 5 + MySQL 5 = A Perfect 10
Adam Trachtenberg
 
PPT
Mysql
guest817344
 
PPTX
Learn PHP Lacture2
ADARSH BHATT
 
PPTX
NCTU ppt 2023-2024_WEEK2-SQL Basics (1).pptx
Amany Saeed
 
PDF
phptut4
tutorialsruby
 
PDF
phptut4
tutorialsruby
 
PDF
Data Integration through Data Virtualization (SQL Server Konferenz 2019)
Cathrine Wilhelmsen
 
PPTX
unit-ii.pptx
NilamHonmane
 
PPTX
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
PPTX
Data types and variables in php for writing and databse
vishal choudhary
 
PPTX
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 
Php summary
Michelle Darling
 
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
MySql:Basics
DataminingTools Inc
 
MySQL Basics
mysql content
 
Making MySQL Agile-ish
Dave Stokes
 
Php 2
tnngo2
 
PHP - Getting good with MySQL part II
Firdaus Adib
 
MySQL Introduction
mysql content
 
MySql:Introduction
DataminingTools Inc
 
PHP 5 + MySQL 5 = A Perfect 10
Adam Trachtenberg
 
Learn PHP Lacture2
ADARSH BHATT
 
NCTU ppt 2023-2024_WEEK2-SQL Basics (1).pptx
Amany Saeed
 
phptut4
tutorialsruby
 
phptut4
tutorialsruby
 
Data Integration through Data Virtualization (SQL Server Konferenz 2019)
Cathrine Wilhelmsen
 
unit-ii.pptx
NilamHonmane
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
Data types and variables in php for writing and databse
vishal choudhary
 
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 

Recently uploaded (20)

PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Controller Request and Response in Odoo18
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Ad

MySQL with PHP

  • 1. Open Source Technology Dr.S Jeyalaksshmi Associate Professor Dept. BCA & IT VISTAS
  • 3. Introduction to MySQL with PHP • A database is your best choice for storing data in your web application, and the MySQL database server has always been the most popular choice among PHP developers. • MySQL uses the SQL (Structured Query Language) programming language to work with the data, and PHP interacts with MySQL by simply passing SQL code through a set of MySQL functions to the MySQL server, which then returns a result that PHP can interpret. 3
  • 4. Creating table in SQL • CREATE TABLE employee ( eid int NOT NULL AUTO_INCREMENT, name varchar(45) NOT NULL, occupation varchar(35) NOT NULL, age int NOT NULL, PRIMARY KEY (id) ); 4
  • 5. How to Create a Database? • A database is defined as an organized collection of data that makes the data easy to access, manage and modify. Generally, databases use SQL (Structured Query Language) for data manipulation. 5
  • 6. To create a database: 1. Open XAMPP Control Panel and start the Apache server and MySQL service. 6
  • 7. STEP 2: In your browser , type localhost in the address bar, and then on the XAMPP dashboard, click on the Phpmyadmin tab. http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/ 7
  • 8. STEP 3: Into the phpmyadmin section, click on new to create a new database. And name your database “db1”. 8
  • 9. STEP 4: Now, create a table named “db1” and create columns as shown below, which you will use on the registration page. 9
  • 10. 10
  • 11. 11
  • 12. 12
  • 13. 1. <?php 2. $con=mysqli_connect('localhost','root','','db1'); database name 3. $check_data=mysqli_query($con,"select * from details"); 4. $check=mysqli_num_rows($check_data); 5. if($check_data){ table name 6. while($row_data=mysqli_fetch_array($check_data)){ 7. echo("ID:".$row_data['ID']."<br>"); 8. echo("NAME:".$row_data['SNAME']."<br>"); 9. echo("AGE:".$row_data['AGE']."<br>"); 10. } server name 11. } username 12. else{ 13. echo ("No data found"); 14. } 15. ?> 13
  • 14. 14
  • 15. How to Edit and Delete Data From the Database? 15
  • 16. <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $pass word); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?> 16
  • 17. if(! $conn ) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully'; mysqli_close($conn); 17
  • 18. if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully"; 18
  • 19. if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo “Connected successfully”; mysqli_close($conn); 19
  • 20. Structured Query Language (SQL) is made up of two sub- languages: • SQL Data Manipulation Language (DML) SELECT statements perform queries INSERT, UPDATE, DELETE statements modify the instance of a table • SQL Data Definition Language (DDL) CREATE, DROP statements modify the database schema GRANT, REVOKE statements enforce the security model 20
  • 21. Find the last names and hire dates of employees who make more than $100000. select LastName, HireDate from Employee where Salary > 100000 21