SlideShare a Scribd company logo
Php verses MySQL
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
Saeid Zebardast
 
SQL Limit in PHP
SQL Limit in PHPSQL Limit in PHP
SQL Limit in PHP
Vineet Kumar Saini
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
Joe Christensen
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
Hassen Poreya
 
SXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup LanguageSXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup Language
elliando dias
 
MySql:Basics
MySql:BasicsMySql:Basics
MySql:Basics
DataminingTools Inc
 
MS Sql Server: Advanced Query Concepts
MS Sql Server: Advanced Query ConceptsMS Sql Server: Advanced Query Concepts
MS Sql Server: Advanced Query Concepts
DataminingTools Inc
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
Vineet Kumar Saini
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
DataminingTools Inc
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
Harit Kothari
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
Vineet Kumar Saini
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
oly07104
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Kazi Uddin Oly
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
Priti Solanki
 

Viewers also liked (9)

Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
CBitss Technologies
 
PHP Training in Chandigarh
PHP Training in ChandigarhPHP Training in Chandigarh
PHP Training in Chandigarh
CBitss Technologies
 
Php verses .net
Php verses .netPhp verses .net
Php verses .net
CBitss Technologies
 
Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
CBitss Technologies
 
Tally training in chandigarh
Tally training in chandigarhTally training in chandigarh
Tally training in chandigarh
CBitss Technologies
 
How to install wordpress
How to install wordpressHow to install wordpress
How to install wordpress
CBitss Technologies
 
Linux training in chandigarh
Linux training in chandigarhLinux training in chandigarh
Linux training in chandigarh
CBitss Technologies
 
Vorrarit Anantsorrarak _Design + Planning_150416_English
Vorrarit Anantsorrarak _Design + Planning_150416_EnglishVorrarit Anantsorrarak _Design + Planning_150416_English
Vorrarit Anantsorrarak _Design + Planning_150416_English
CooLBiere A
 
Marius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer Snr Systems Engineer InfrographicMarius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer
 
Vorrarit Anantsorrarak _Design + Planning_150416_English
Vorrarit Anantsorrarak _Design + Planning_150416_EnglishVorrarit Anantsorrarak _Design + Planning_150416_English
Vorrarit Anantsorrarak _Design + Planning_150416_English
CooLBiere A
 
Marius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer Snr Systems Engineer InfrographicMarius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer Snr Systems Engineer Infrographic
Marius Dreyer
 

Similar to Php verses MySQL (20)

PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
wahidullah mudaser
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
Sankhadeep Roy
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
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
saritasingh19866
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
StephenEfange3
 
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
Vineet Kumar Saini
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
Terry Yoast
 
Php summary
Php summaryPhp summary
Php summary
Michelle Darling
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
Mudasir Syed
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti 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 Newbies
Dave Stokes
 
UNIT V (5).pptx
UNIT V (5).pptxUNIT V (5).pptx
UNIT V (5).pptx
DrDhivyaaCRAssistant
 
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
Dhivyaa C.R
 
Php 2
Php 2Php 2
Php 2
tnngo2
 
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
KingKhaliilHayat
 
Php mysq
Php mysqPhp mysq
Php mysq
prasanna pabba
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
mebratu9
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
Inbal Geffen
 
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
Arti Parab Academics
 
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
saritasingh19866
 
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
Vineet Kumar Saini
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
Terry Yoast
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti 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 Newbies
Dave 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 College
Dhivyaa 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.docx
KingKhaliilHayat
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
mebratu9
 
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
Arti Parab Academics
 

Recently uploaded (20)

How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 

Php verses MySQL

  • 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 : [email protected]