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

PPTX
Php verses my sql
PPT
Lecture6 display data by okello erick
PPT
PHP - Getting good with MySQL part II
PDF
Using php with my sql
PPTX
Database Connectivity in PHP
PDF
Introduction to php database connectivity
PDF
4.3 MySQL + PHP
Php verses my sql
Lecture6 display data by okello erick
PHP - Getting good with MySQL part II
Using php with my sql
Database Connectivity in PHP
Introduction to php database connectivity
4.3 MySQL + PHP

What's hot (16)

PDF
MySQL for beginners
PDF
SQL Limit in PHP
PPT
MYSQL - PHP Database Connectivity
PPT
Mysql DBI
PPTX
Learn PHP Lacture2
PDF
Web app development_crud_13
PDF
SXML: S-expression eXtensible Markup Language
PPTX
MySql:Basics
PPTX
MS Sql Server: Advanced Query Concepts
PDF
Delete statement in PHP
PPTX
MySql:Introduction
ODP
Database Connection With Mysql
PDF
Update statement in PHP
PPTX
Introduction to database
PPTX
Introduction to database
PPTX
Beginner guide to mysql command line
MySQL for beginners
SQL Limit in PHP
MYSQL - PHP Database Connectivity
Mysql DBI
Learn PHP Lacture2
Web app development_crud_13
SXML: S-expression eXtensible Markup Language
MySql:Basics
MS Sql Server: Advanced Query Concepts
Delete statement in PHP
MySql:Introduction
Database Connection With Mysql
Update statement in PHP
Introduction to database
Introduction to database
Beginner guide to mysql command line
Ad

Viewers also liked (9)

PDF
Linux training in chandigarh
PPTX
PHP Training in Chandigarh
PPTX
Php verses .net
PDF
Linux training in chandigarh
PDF
Tally training in chandigarh
PDF
How to install wordpress
PPT
Linux training in chandigarh
PDF
Vorrarit Anantsorrarak _Design + Planning_150416_English
PDF
Marius Dreyer Snr Systems Engineer Infrographic
Linux training in chandigarh
PHP Training in Chandigarh
Php verses .net
Linux training in chandigarh
Tally training in chandigarh
How to install wordpress
Linux training in chandigarh
Vorrarit Anantsorrarak _Design + Planning_150416_English
Marius Dreyer Snr Systems Engineer Infrographic
Ad

Similar to Php verses MySQL (20)

PDF
PHP with MySQL
PDF
PHP and Mysql
PPT
Php with MYSQL Database
PPT
Synapse india reviews on php and sql
PPTX
Using Mysql.pptx
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
PPT
9780538745840 ppt ch08
PDF
Php summary
PPT
Php Mysql
PPT
Php MySql For Beginners
PDF
All Things Open 2016 -- Database Programming for Newbies
PPTX
UNIT V (5).pptx
PPTX
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
PDF
Php 2
DOCX
Collection of built in functions for manipulating MySQL databases.docx
PPTX
Php mysq
PPT
Php and MySQL Web Development
PPTX
Chapter 3.1.pptx
PDF
Mysql & Php
PHP with MySQL
PHP and Mysql
Php with MYSQL Database
Synapse india reviews on php and sql
Using Mysql.pptx
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Pyhton with Mysql to perform CRUD operations.pptx
9780538745840 ppt ch08
Php summary
Php Mysql
Php MySql For Beginners
All Things Open 2016 -- Database Programming for Newbies
UNIT V (5).pptx
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Php 2
Collection of built in functions for manipulating MySQL databases.docx
Php mysq
Php and MySQL Web Development
Chapter 3.1.pptx
Mysql & Php

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Insiders guide to clinical Medicine.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Institutional Correction lecture only . . .
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
VCE English Exam - Section C Student Revision Booklet
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Insiders guide to clinical Medicine.pdf
Complications of Minimal Access Surgery at WLH
Institutional Correction lecture only . . .
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O5-L3 Freight Transport Ops (International) V1.pdf

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 : navneetlinuxexpert@gmail.com