SlideShare a Scribd company logo
Php verses my sql
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

PDF
Php verses MySQL
CBitss Technologies
 
PPT
Lecture6 display data by okello erick
okelloerick
 
PDF
Php 2
tnngo2
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PDF
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Mysql DBI
Joe Christensen
 
PDF
MySQL for beginners
Saeid Zebardast
 
PPTX
Learn PHP Lacture2
ADARSH BHATT
 
Php verses MySQL
CBitss Technologies
 
Lecture6 display data by okello erick
okelloerick
 
Php 2
tnngo2
 
Database Connectivity in PHP
Taha Malampatti
 
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Mysql DBI
Joe Christensen
 
MySQL for beginners
Saeid Zebardast
 
Learn PHP Lacture2
ADARSH BHATT
 

What's hot (15)

PDF
SXML: S-expression eXtensible Markup Language
elliando dias
 
PPTX
MySql:Basics
DataminingTools Inc
 
PPTX
MySql:Introduction
DataminingTools Inc
 
PDF
Web app development_crud_13
Hassen Poreya
 
PDF
Delete statement in PHP
Vineet Kumar Saini
 
PPTX
MS Sql Server: Advanced Query Concepts
DataminingTools Inc
 
PDF
Update statement in PHP
Vineet Kumar Saini
 
PDF
SQL Limit in PHP
Vineet Kumar Saini
 
PPTX
Introduction to database
oly07104
 
PPTX
Introduction to database
Kazi Uddin Oly
 
PPTX
MS SQL Database basic
wali1195189
 
DOCX
Conexion php
Luis Reategui Vargas
 
DOCX
Php mysql connectivity
abhikwb
 
PDF
Python my SQL - create table
Learnbay Datascience
 
PDF
Python my sql database connection
Learnbay Datascience
 
SXML: S-expression eXtensible Markup Language
elliando dias
 
MySql:Basics
DataminingTools Inc
 
MySql:Introduction
DataminingTools Inc
 
Web app development_crud_13
Hassen Poreya
 
Delete statement in PHP
Vineet Kumar Saini
 
MS Sql Server: Advanced Query Concepts
DataminingTools Inc
 
Update statement in PHP
Vineet Kumar Saini
 
SQL Limit in PHP
Vineet Kumar Saini
 
Introduction to database
oly07104
 
Introduction to database
Kazi Uddin Oly
 
MS SQL Database basic
wali1195189
 
Conexion php
Luis Reategui Vargas
 
Php mysql connectivity
abhikwb
 
Python my SQL - create table
Learnbay Datascience
 
Python my sql database connection
Learnbay Datascience
 
Ad

Similar to Php verses my sql (20)

PDF
Php verses MySQL
CBitss Technologies
 
PPT
Php MySql For Beginners
Priti Solanki
 
PDF
PHP with MySQL
wahidullah mudaser
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PDF
PHP and Mysql
Sankhadeep Roy
 
PPTX
Class 8 - Database Programming
Ahmed Swilam
 
PPT
SQL -PHP Tutorial
Information Technology
 
PPTX
PHP and MySQL.pptx
natesanp1234
 
PPTX
chapter_Seven Database manipulation using php.pptx
Getawu
 
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Vineet Kumar Saini
 
PDF
Mysql & Php
Inbal Geffen
 
PPTX
Php mysq
prasanna pabba
 
PDF
Database connectivity in PHP
Vineet Kumar Saini
 
PDF
lab56_db
tutorialsruby
 
PDF
lab56_db
tutorialsruby
 
PPT
PHP - Getting good with MySQL part II
Firdaus Adib
 
PDF
Introduction to MySQL and introduction to basic queries
anishacotta2
 
PPT
My sql with querys
NIRMAL FELIX
 
DOCX
Sql full tutorial
Mozaaic Cyber Security
 
Php verses MySQL
CBitss Technologies
 
Php MySql For Beginners
Priti Solanki
 
PHP with MySQL
wahidullah mudaser
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PHP and Mysql
Sankhadeep Roy
 
Class 8 - Database Programming
Ahmed Swilam
 
SQL -PHP Tutorial
Information Technology
 
PHP and MySQL.pptx
natesanp1234
 
chapter_Seven Database manipulation using php.pptx
Getawu
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Vineet Kumar Saini
 
Mysql & Php
Inbal Geffen
 
Php mysq
prasanna pabba
 
Database connectivity in PHP
Vineet Kumar Saini
 
lab56_db
tutorialsruby
 
lab56_db
tutorialsruby
 
PHP - Getting good with MySQL part II
Firdaus Adib
 
Introduction to MySQL and introduction to basic queries
anishacotta2
 
My sql with querys
NIRMAL FELIX
 
Sql full tutorial
Mozaaic Cyber Security
 
Ad

Recently uploaded (20)

PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
MariellaTBesana
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Landforms and landscapes data surprise preview
jpinnuck
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
Understanding operators in c language.pptx
auteharshil95
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
MariellaTBesana
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 

Php verses my sql

  • 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]