SlideShare a Scribd company logo
1 of 14
PHP-MySQl Connectivity
What is the use of PHP and MySQL?
PHP is the most popular scripting language for web
development. It is free, open source and server-side (the
code is executed on the server). MySQL is a Relational
Database Management System (RDBMS) that uses
Structured Query Language (SQL).
How to connect PHP with MySQl?
Step 1: Connecting to MySQl Server
 mysql_connect(‘host _name’ , ’username’ , ’password’);
Step 2: Selecting Database
 mysql_select_database(‘Database Name’);
Step 3: Query Execution
 mysql_query(‘Query to be Executed’);
Step 1: Connecting to MySQl Server
mysql_connect(‘host _name’ , ’username’ , ’password’);
Eg: mysql_connect(‘localhost’ , ‘root’ , ’’);
Step 2: Selecting Database
mysql_select_database(‘Database Name’);
Eg: mysql_select_database(‘CACMS_db’);
Step 3: Query Execution
mysql_query(‘Query to be Executed’);
mysql_query(“Update table CACMS_tbl set institute _name=‘CACMS’ ”);
Example Program
<html>
<body>
<form action=“ ” method=Post>
<input type=“text” name=“name”>
<input type=“email” name =“email”>
<input type=“submit” value=“Register”
name=“Button”>
</form>
</body>
</html>
Registration.PHP will look like this
<?php
mysql_connect(“localhost”, “root”, “”);
mysql_CACMS_db(“test”);
if(isset($_POST[‘Button’])){
mysql_query(“INSERT INTO tbl_student(sname,email)
values(‘$_POST[name]’, ‘$_POST[email],…”);
echo “Successfully Inserted”;
?>
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 above will return one row from table at a time and
then next. So, usually we use these functions along with
while loop.
MySQl _fetch_array()
$query=mysql_query(“select * from tbl_cacms”);
while($fetch=mysql_fetch_array($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[‘vchr_phone’]; //print second column the
retrieved row
}
MySQl _fetch_row()
$query=mysql_query(“select * from tbl_cacms”);
while($fetch=mysql_fetch_row($query))
{
echo $fetch[0]; //prints first column the retrieved row
echo $fetch[1]; //print second column the retrieved
row
}
MySQl _fetch_assoc()
$query=mysql_query(“select * from tbl_cacms”);
while($fetch=mysql_fetch_assoc($query))
{
echo $fetch[‘vchr_sname’]; //prints first column the
retrieved row
echo $fetch[‘vchr_phone’]; //print second column the
retrieved row
}
MySQl _fetch_object()
$query=mysql_query(“select * from tbl_cacms”);
while($fetch=mysql_fetch_object($query))
{
echo $fetch->’vchr_sname’; //prints first column the
retrieved row
echo $fetch->‘vchr_phone’; //print second column the
retrieved row
}
Contact Us:
SCO-88, District Shopping Complex
Ranjit Avenue, Amritsar
Website:- http://www.cacms.in
Contact No. -8288040281, 8968268200

More Related Content

What's hot

1 serializando y deserializando datos en red
1  serializando y deserializando datos en red1  serializando y deserializando datos en red
1 serializando y deserializando datos en red
Jesús Estévez
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
Harit Kothari
 
4 exercises for part 1
4   exercises for part 14   exercises for part 1
4 exercises for part 1
drewz lin
 

What's hot (20)

DDP - Meteor
DDP - MeteorDDP - Meteor
DDP - Meteor
 
Running Node Applications on iOS and Android
Running Node Applications on iOS and AndroidRunning Node Applications on iOS and Android
Running Node Applications on iOS and Android
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
1 serializando y deserializando datos en red
1  serializando y deserializando datos en red1  serializando y deserializando datos en red
1 serializando y deserializando datos en red
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
 
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
 
Node.js
Node.jsNode.js
Node.js
 
Containers > VMs
Containers > VMsContainers > VMs
Containers > VMs
 
NoSql Injection
NoSql InjectionNoSql Injection
NoSql Injection
 
Building HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDBBuilding HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDB
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
4 exercises for part 1
4   exercises for part 14   exercises for part 1
4 exercises for part 1
 
Java Session
Java SessionJava Session
Java Session
 
Cookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesServiceCookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesService
 
Php
PhpPhp
Php
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
ExpressJs Session01
ExpressJs Session01ExpressJs Session01
ExpressJs Session01
 

Similar to PHP-MySQl Connectivity

Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptx
cavicav231
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
AkramWaseem
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
AkramWaseem
 
Accessing_MySQL_from_Ruby
Accessing_MySQL_from_RubyAccessing_MySQL_from_Ruby
Accessing_MySQL_from_Ruby
tutorialsruby
 
Accessing_MySQL_from_Ruby
Accessing_MySQL_from_RubyAccessing_MySQL_from_Ruby
Accessing_MySQL_from_Ruby
tutorialsruby
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?
Gavin Holt
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
HiteshNandi
 

Similar to PHP-MySQl Connectivity (20)

Connecting to my sql using PHP
Connecting to my sql using PHPConnecting to my sql using PHP
Connecting to my sql using PHP
 
harry presentation
harry presentationharry presentation
harry presentation
 
Node.js with MySQL.pdf
Node.js with MySQL.pdfNode.js with MySQL.pdf
Node.js with MySQL.pdf
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Mysql
MysqlMysql
Mysql
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptx
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
 
Sql installation
Sql installationSql installation
Sql installation
 
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
 
Accessing_MySQL_from_Ruby
Accessing_MySQL_from_RubyAccessing_MySQL_from_Ruby
Accessing_MySQL_from_Ruby
 
Accessing_MySQL_from_Ruby
Accessing_MySQL_from_RubyAccessing_MySQL_from_Ruby
Accessing_MySQL_from_Ruby
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?
 
Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 

PHP-MySQl Connectivity

  • 2. What is the use of PHP and MySQL? PHP is the most popular scripting language for web development. It is free, open source and server-side (the code is executed on the server). MySQL is a Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).
  • 3. How to connect PHP with MySQl? Step 1: Connecting to MySQl Server  mysql_connect(‘host _name’ , ’username’ , ’password’); Step 2: Selecting Database  mysql_select_database(‘Database Name’); Step 3: Query Execution  mysql_query(‘Query to be Executed’);
  • 4. Step 1: Connecting to MySQl Server mysql_connect(‘host _name’ , ’username’ , ’password’); Eg: mysql_connect(‘localhost’ , ‘root’ , ’’);
  • 5. Step 2: Selecting Database mysql_select_database(‘Database Name’); Eg: mysql_select_database(‘CACMS_db’);
  • 6. Step 3: Query Execution mysql_query(‘Query to be Executed’); mysql_query(“Update table CACMS_tbl set institute _name=‘CACMS’ ”);
  • 7. Example Program <html> <body> <form action=“ ” method=Post> <input type=“text” name=“name”> <input type=“email” name =“email”> <input type=“submit” value=“Register” name=“Button”> </form> </body> </html>
  • 8. Registration.PHP will look like this <?php mysql_connect(“localhost”, “root”, “”); mysql_CACMS_db(“test”); if(isset($_POST[‘Button’])){ mysql_query(“INSERT INTO tbl_student(sname,email) values(‘$_POST[name]’, ‘$_POST[email],…”); echo “Successfully Inserted”; ?>
  • 9. 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 above will return one row from table at a time and then next. So, usually we use these functions along with while loop.
  • 10. MySQl _fetch_array() $query=mysql_query(“select * from tbl_cacms”); while($fetch=mysql_fetch_array($query)) { echo $fetch[0]; //prints first column the retrieved row echo $fetch[‘vchr_phone’]; //print second column the retrieved row }
  • 11. MySQl _fetch_row() $query=mysql_query(“select * from tbl_cacms”); while($fetch=mysql_fetch_row($query)) { echo $fetch[0]; //prints first column the retrieved row echo $fetch[1]; //print second column the retrieved row }
  • 12. MySQl _fetch_assoc() $query=mysql_query(“select * from tbl_cacms”); while($fetch=mysql_fetch_assoc($query)) { echo $fetch[‘vchr_sname’]; //prints first column the retrieved row echo $fetch[‘vchr_phone’]; //print second column the retrieved row }
  • 13. MySQl _fetch_object() $query=mysql_query(“select * from tbl_cacms”); while($fetch=mysql_fetch_object($query)) { echo $fetch->’vchr_sname’; //prints first column the retrieved row echo $fetch->‘vchr_phone’; //print second column the retrieved row }
  • 14. Contact Us: SCO-88, District Shopping Complex Ranjit Avenue, Amritsar Website:- http://www.cacms.in Contact No. -8288040281, 8968268200