SlideShare ist ein Scribd-Unternehmen logo
1 von 39
WELCOME
INTRODUCTION TO
PHP-MySQL CONNECTIVITY
What you Benefit ???
By the end of this session you will learn how to use PHP to
● Store the data into database.
● Retrieve data from the backend database in real-time.
TASK OF THE DAY
Create the registration form shown here and store the data passed with it into a
database .
INTRODUCTION TO PHP DATABASE
CONNECTIVITY
Introduction To PHP Database
Connectivity
We had already tried passing data to a server .
But..where do we store this data and how…?
How To Connect PHP to Database?
Step 1 : Connecting to MySQL Server
Step 2 : Selecting Database
Step 3 : Query Execution
STEP 1 -
CONNECTING TO MySQL SERVER
mysql_connect(‘host_name’,’username’,’password’);
Eg: mysql_connect(‘localhost’,’root’,’root’);
STEP 2-
SELECTING DATABASE
mysql_select_db(‘Database Name’);
Eg: mysql_select_db(‘baabtra_db’);
STEP 3-
QUERY EXECUTION
mysql_query(“query to be executed”);
Eg: mysql_query(“update table baabtra_mentees_tbl
set vchr_cmpny_name=’Baabtra’
where pk_int_branch_id=’Caffit’ ”);
Let’s TRY
Why don’t we make it even more interesting by implementing this with our task.
So let’s start
TASK
Step1: Create the Registration form
STEP 1
Registration.html
Step2
Step 2: Now create a database to store the data passed from registration form
Step 2
Lets create the database
create database company_baabtra;
Create a table tbl_baabtra_mentees as shown here
Step 3
Step 3: Retrieve the data passed using POST method from register_action.php
Checks if button click is set
File upload
Reading the
checked values from
checkbox
Step 4
Step 4: Data is now available at register_action.php. So next step is to store this
data into the database.
Step 4
register_action.php
Connects to remote server
Step 4
register_action.php
Selects the database
Step 4
register_action.php Executes the mysql query to
store the registered mentee
information into database
Step 5
Step 5: Run your registration form from the localhost now
Step 5
Step 6
Step 6: Check your database. It should be updated somewhat like that
Connecting Database to PHP
Now how do we fetch the data stored in database from frontend ??
Retrieving Data From MySQL
There are four different ways to fetch the data from database using PHP.
▪ Mysql_fetch_array()
▪ Mysql_fetch_row()
▪ Mysql_fetch_assoc()
▪ Mysql_fetch_object()
All of the above will return one row from table at a time and then the next row
and so on . So usually we use these functions along with a while loop
mysql_fetch_row()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_row($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[1]; //prints second column the retrieved row
}
mysql_fetch_assoc()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_assoc($query))
{
echo $fetch[‘vchr_uname’]; //prints first column the retrieved row
echo $fetch[‘vchr_phone’]; //prints second column the retrieved row
}
mysql_fetch_array()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_array($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[‘vchr_phone’]; //prints second column the retrieved row
}
mysql_fetch_object()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_object($query))
{
echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row
echo $fetch -> ‘vchr_phone’; //prints second column the retrieved row
}
mysql_fetch_object()
$query = mysql_query (“select * from tbl_baabtra_mentees");
while($fetch=mysql_fetch_object($query))
{
echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row
echo $fetch -> ‘vchr_phone’; //prints second column the retrieved row
}
“Returns an object with properties that correspond to the fetched row and moves
the internal data pointer ahead.”
Okay…!!
So what are we waiting for now..??
Lets do it then
Let’s Get Back With Our Task
Step 7: Set a header to redirect from
‘register_action.php’ to ‘view_baabtra_mentees.php’
header(‘Location: view_baabtra_mentees.php’);
Let’s Get Back With Our Task
Step 8: Now fetch the data from tbl_baabtra_mentees and display it in a
table format.
Step 8
uses mysql_fetch_row function.
returns each row of data from the
mysql table
Step 8
fetches using the column
number
Step 9
Step 9: Run the registration form from localhost now
Step 9
On Submit it displays the list of mentees registered
Woooh….!!! That really works…
So we are done with our TASK of the day.
That was great…!!!
END OF THE SESSION

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Java rmi
Java rmiJava rmi
Java rmi
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
JDBC
JDBCJDBC
JDBC
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Operators php
Operators phpOperators php
Operators php
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php string function
Php string function Php string function
Php string function
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Data types in php
Data types in phpData types in php
Data types in php
 

Andere mochten auch

Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With MysqlHarit Kothari
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introductionProgrammer Blog
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and SessionsNisa Soomro
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
PHP MYSQL And IIS2.ppt
PHP MYSQL And IIS2.pptPHP MYSQL And IIS2.ppt
PHP MYSQL And IIS2.pptwebhostingguy
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For BeginnersPriti Solanki
 
Cookies PowerPoint
Cookies PowerPointCookies PowerPoint
Cookies PowerPointemurfield
 

Andere mochten auch (20)

Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Session 2 django material for training at baabtra models
Session 2 django material for training at baabtra modelsSession 2 django material for training at baabtra models
Session 2 django material for training at baabtra models
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
PHP MYSQL And IIS2.ppt
PHP MYSQL And IIS2.pptPHP MYSQL And IIS2.ppt
PHP MYSQL And IIS2.ppt
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
 
Cookies PowerPoint
Cookies PowerPointCookies PowerPoint
Cookies PowerPoint
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Ähnlich wie Php database connectivity

Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sqlsalissal
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Developmentw3ondemand
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHPDifference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHPVineet Kumar Saini
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile appsIvano Malavolta
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part IIFirdaus Adib
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...DicodingEvent
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Databasedharawagh9999
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectJonathan Wage
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4JoeDinaso
 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientDimitar Ivanov
 

Ähnlich wie Php database connectivity (20)

Introduction to php database connectivity
Introduction to php  database connectivityIntroduction to php  database connectivity
Introduction to php database connectivity
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHPDifference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile apps
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
UNIT V (5).pptx
UNIT V (5).pptxUNIT V (5).pptx
UNIT V (5).pptx
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
 
Php basics
Php basicsPhp basics
Php basics
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
24. SQL .pdf
24. SQL .pdf24. SQL .pdf
24. SQL .pdf
 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP Client
 

Mehr von baabtra.com - No. 1 supplier of quality freshers

Mehr von baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 
Apple iwatches
Apple iwatchesApple iwatches
Apple iwatches
 

Kürzlich hochgeladen

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 

Kürzlich hochgeladen (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Php database connectivity

  • 3. What you Benefit ??? By the end of this session you will learn how to use PHP to ● Store the data into database. ● Retrieve data from the backend database in real-time.
  • 4. TASK OF THE DAY Create the registration form shown here and store the data passed with it into a database .
  • 5. INTRODUCTION TO PHP DATABASE CONNECTIVITY
  • 6. Introduction To PHP Database Connectivity We had already tried passing data to a server . But..where do we store this data and how…?
  • 7. How To Connect PHP to Database? Step 1 : Connecting to MySQL Server Step 2 : Selecting Database Step 3 : Query Execution
  • 8. STEP 1 - CONNECTING TO MySQL SERVER mysql_connect(‘host_name’,’username’,’password’); Eg: mysql_connect(‘localhost’,’root’,’root’);
  • 9. STEP 2- SELECTING DATABASE mysql_select_db(‘Database Name’); Eg: mysql_select_db(‘baabtra_db’);
  • 10. STEP 3- QUERY EXECUTION mysql_query(“query to be executed”); Eg: mysql_query(“update table baabtra_mentees_tbl set vchr_cmpny_name=’Baabtra’ where pk_int_branch_id=’Caffit’ ”);
  • 11. Let’s TRY Why don’t we make it even more interesting by implementing this with our task. So let’s start
  • 12. TASK Step1: Create the Registration form
  • 14. Step2 Step 2: Now create a database to store the data passed from registration form
  • 15. Step 2 Lets create the database create database company_baabtra; Create a table tbl_baabtra_mentees as shown here
  • 16. Step 3 Step 3: Retrieve the data passed using POST method from register_action.php Checks if button click is set File upload Reading the checked values from checkbox
  • 17. Step 4 Step 4: Data is now available at register_action.php. So next step is to store this data into the database.
  • 20. Step 4 register_action.php Executes the mysql query to store the registered mentee information into database
  • 21. Step 5 Step 5: Run your registration form from the localhost now
  • 23. Step 6 Step 6: Check your database. It should be updated somewhat like that
  • 24. Connecting Database to PHP Now how do we fetch the data stored in database from frontend ??
  • 25. Retrieving Data From MySQL There are four different ways to fetch the data from database using PHP. ▪ Mysql_fetch_array() ▪ Mysql_fetch_row() ▪ Mysql_fetch_assoc() ▪ Mysql_fetch_object() All of the above will return one row from table at a time and then the next row and so on . So usually we use these functions along with a while loop
  • 26. mysql_fetch_row() $query = mysql_query (“select * from tbl_baabtra_mentees"); while($fetch=mysql_fetch_row($query)) { echo $fetch[0]; //prints first column the retrieved row echo $fetch[1]; //prints second column the retrieved row }
  • 27. mysql_fetch_assoc() $query = mysql_query (“select * from tbl_baabtra_mentees"); while($fetch=mysql_fetch_assoc($query)) { echo $fetch[‘vchr_uname’]; //prints first column the retrieved row echo $fetch[‘vchr_phone’]; //prints second column the retrieved row }
  • 28. mysql_fetch_array() $query = mysql_query (“select * from tbl_baabtra_mentees"); while($fetch=mysql_fetch_array($query)) { echo $fetch[0]; //prints first column the retrieved row echo $fetch[‘vchr_phone’]; //prints second column the retrieved row }
  • 29. mysql_fetch_object() $query = mysql_query (“select * from tbl_baabtra_mentees"); while($fetch=mysql_fetch_object($query)) { echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row echo $fetch -> ‘vchr_phone’; //prints second column the retrieved row }
  • 30. mysql_fetch_object() $query = mysql_query (“select * from tbl_baabtra_mentees"); while($fetch=mysql_fetch_object($query)) { echo $fetch -> ‘vchr_uname’; //prints first column the retrieved row echo $fetch -> ‘vchr_phone’; //prints second column the retrieved row } “Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.”
  • 31. Okay…!! So what are we waiting for now..?? Lets do it then
  • 32. Let’s Get Back With Our Task Step 7: Set a header to redirect from ‘register_action.php’ to ‘view_baabtra_mentees.php’ header(‘Location: view_baabtra_mentees.php’);
  • 33. Let’s Get Back With Our Task Step 8: Now fetch the data from tbl_baabtra_mentees and display it in a table format.
  • 34. Step 8 uses mysql_fetch_row function. returns each row of data from the mysql table
  • 35. Step 8 fetches using the column number
  • 36. Step 9 Step 9: Run the registration form from localhost now
  • 37. Step 9 On Submit it displays the list of mentees registered
  • 38. Woooh….!!! That really works… So we are done with our TASK of the day. That was great…!!!
  • 39. END OF THE SESSION