SlideShare a Scribd company logo
1 of 13
Download to read offline
Introduction
• What is MySql ?
MySql is an open source relational database
management system.
• How MySql is related to PHP?
MySql acts as a back-end database server and
helps in data storage and management of data
stored at MySql database server.
Predefined Constant
MySql Fetch Constant :
• MYSQL_ASSOC : Columns are returned into the array
having the fieldname as the array index.
• MYSQL_BOTH : Columns are returned into the array
having both a numerical index and the field name as the array
index.
• MYSQL_NUM : Columns are returned into the array having
a numerical index to the fields. This index is start with 0, the
first field in the result.
PHP MySql Function
mysql_connect : Open a connection to a MySql server.
mysql_close : Close MySql connection.
mysql_create_db : Create a MySql database.
mysql_error : Returns the text of the error message
from previous MySql operation.
mysql_fetch_assoc : Fetch a result row as an
associative array.
mysql_select_db : Select a MySql database.
How to connect to MySql via PHP.
<?php
$host = "localhost";
$username = "root";
$password = "";
mysql_connect($host,$username,$password)
or die(mysql_error());
?>
How to Select database in a table.
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbemp") or die(mysql_error());
$result=mysql_query("select * from emp")
or die(mysql_error());
$row=mysql_fetch_array($result);
echo "<br>Roll:".$row['empno'];
echo "<br>Name:".$row['name'];
echo "<br>Roll:".$row['Job'];
?>
How to select values from MySql table.
<?php
mysql_connect("localhost", "root", "") or
die(mysql_error());
mysql_select_db("dbemp") or die(mysql_error());
$result=mysql_query("select * from emp")
or die(mysql_error());
echo "<table width='20%' bgcolor='lime' border='4'
bordercolor='green'>";
echo "<tr> <th>Empno</th> <th>Name</th> </tr>";
Contin…
while($row = mysql_fetch_array( $result ))
{
echo "<tr> <td>";
echo $row['empno'];
echo "</td> <td>";
echo $row['name'];
echo "</td></tr>";
}
echo "</table>";
?>
Display data from database using fetch_assoc function
$sql = "SELECT empno, name,Job FROM emp";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{while($row = $result->fetch_assoc())
{ echo "<br> Empno: ". $row["empno"]. " Name: ". $row["name"]. " Job:"
. $row["Job"] . "<br>";
} }
else
{ echo "Can't find the record"; }
$conn->close();
?>
How to insert data in a MySql Table.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "INSERT INTO emp (ename,job, sal) VALUES
('Amit','manager','3333')";
Contin…
mysql_select_db('dbemp');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfullyn";
mysql_close($conn);
?>
CBitss Technologies provide a PHP training
in Chandigarh. A well qualified trainer will
train you on all sophisticated technologies.
CBitss Technologies is ISO 9001:2008
certified PHP training institute in
Chandigarh.
Office : SCO 23-24-25, Level 3 ,
Near Passport office, Above
Allahabad Bank,
Sec 34A,Chandigarh.
Phone : 9988741983
Website : http://goo.gl/aO9a4u
Email : navneetlinuxexpert@gmail.com

More Related Content

What's hot (16)

MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
SQL Limit in PHP
SQL Limit in PHPSQL Limit in PHP
SQL Limit in PHP
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
 
SXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup LanguageSXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup Language
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
 
MS Sql Server: Advanced Query Concepts
MS Sql Server: Advanced Query ConceptsMS Sql Server: Advanced Query Concepts
MS Sql Server: Advanced Query Concepts
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
 

Viewers also liked

Viewers also liked (7)

Mtkbab3 dan4ratna
Mtkbab3 dan4ratnaMtkbab3 dan4ratna
Mtkbab3 dan4ratna
 
MKT 571 Final Exam Answers 2015 version
MKT 571 Final Exam Answers 2015 versionMKT 571 Final Exam Answers 2015 version
MKT 571 Final Exam Answers 2015 version
 
Tugas mtk
Tugas mtkTugas mtk
Tugas mtk
 
Gametogenesisdagnishernandez
GametogenesisdagnishernandezGametogenesisdagnishernandez
Gametogenesisdagnishernandez
 
Living with noise?
Living with noise?Living with noise?
Living with noise?
 
Valoració dels resultats de la COP21
Valoració dels resultats de la COP21Valoració dels resultats de la COP21
Valoració dels resultats de la COP21
 
День российской печати 2017
День российской печати 2017День российской печати 2017
День российской печати 2017
 

Similar to MySQL PHP Guide

Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sqlsaritasingh19866
 
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
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08Terry Yoast
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For BeginnersPriti Solanki
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
 
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
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxKingKhaliilHayat
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Developmentw3ondemand
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptxmebratu9
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQLArti Parab Academics
 

Similar to MySQL PHP Guide (20)

PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
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
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 
Php summary
Php summaryPhp summary
Php summary
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
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
 
Php 2
Php 2Php 2
Php 2
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docx
 
Php mysq
Php mysqPhp mysq
Php mysq
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
 

More from CBitss Technologies

More from CBitss Technologies (11)

Tally training in chandigarh
Tally training in chandigarhTally training in chandigarh
Tally training in chandigarh
 
Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
 
Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
 
Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
How to install wordpress
How to install wordpressHow to install wordpress
How to install wordpress
 
Php verses .net
Php verses .netPhp verses .net
Php verses .net
 
Php training in chandigarh
Php training in chandigarhPhp training in chandigarh
Php training in chandigarh
 
Android training in chandigarh
Android training in chandigarhAndroid training in chandigarh
Android training in chandigarh
 
web designing course in chandigarh
web designing course in chandigarhweb designing course in chandigarh
web designing course in chandigarh
 
PHP Training in Chandigarh
PHP Training in ChandigarhPHP Training in Chandigarh
PHP Training in Chandigarh
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

MySQL PHP Guide

  • 1.
  • 2. Introduction • What is MySql ? MySql is an open source relational database management system. • How MySql is related to PHP? MySql acts as a back-end database server and helps in data storage and management of data stored at MySql database server.
  • 3. Predefined Constant MySql Fetch Constant : • MYSQL_ASSOC : Columns are returned into the array having the fieldname as the array index. • MYSQL_BOTH : Columns are returned into the array having both a numerical index and the field name as the array index. • MYSQL_NUM : Columns are returned into the array having a numerical index to the fields. This index is start with 0, the first field in the result.
  • 4. PHP MySql Function mysql_connect : Open a connection to a MySql server. mysql_close : Close MySql connection. mysql_create_db : Create a MySql database. mysql_error : Returns the text of the error message from previous MySql operation. mysql_fetch_assoc : Fetch a result row as an associative array. mysql_select_db : Select a MySql database.
  • 5. How to connect to MySql via PHP. <?php $host = "localhost"; $username = "root"; $password = ""; mysql_connect($host,$username,$password) or die(mysql_error()); ?>
  • 6. How to Select database in a table. <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("dbemp") or die(mysql_error()); $result=mysql_query("select * from emp") or die(mysql_error()); $row=mysql_fetch_array($result); echo "<br>Roll:".$row['empno']; echo "<br>Name:".$row['name']; echo "<br>Roll:".$row['Job']; ?>
  • 7. How to select values from MySql table. <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("dbemp") or die(mysql_error()); $result=mysql_query("select * from emp") or die(mysql_error()); echo "<table width='20%' bgcolor='lime' border='4' bordercolor='green'>"; echo "<tr> <th>Empno</th> <th>Name</th> </tr>";
  • 8. Contin… while($row = mysql_fetch_array( $result )) { echo "<tr> <td>"; echo $row['empno']; echo "</td> <td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; ?>
  • 9. Display data from database using fetch_assoc function $sql = "SELECT empno, name,Job FROM emp"; $result = $conn->query($sql); if ($result->num_rows > 0) {while($row = $result->fetch_assoc()) { echo "<br> Empno: ". $row["empno"]. " Name: ". $row["name"]. " Job:" . $row["Job"] . "<br>"; } } else { echo "Can't find the record"; } $conn->close(); ?>
  • 10. How to insert data in a MySql Table. <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = "INSERT INTO emp (ename,job, sal) VALUES ('Amit','manager','3333')";
  • 11. Contin… mysql_select_db('dbemp'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfullyn"; mysql_close($conn); ?>
  • 12. CBitss Technologies provide a PHP training in Chandigarh. A well qualified trainer will train you on all sophisticated technologies. CBitss Technologies is ISO 9001:2008 certified PHP training institute in Chandigarh.
  • 13. Office : SCO 23-24-25, Level 3 , Near Passport office, Above Allahabad Bank, Sec 34A,Chandigarh. Phone : 9988741983 Website : http://goo.gl/aO9a4u Email : navneetlinuxexpert@gmail.com