SlideShare a Scribd company logo
PHP Database Handling
• Name: Kunj Desai
• Enrollment : 140950107022
• Branch: CSE-A
• Year: 2017
INTRODUCTION:
• Most interactive websites nowadays require data to be presented dynamically and
interactively based on input from the user. For example, a customer may need to log into a
retail website to check his purchasing history. In this instance, the website would have
stored two types of data in order for the customer to perform the check – the customer’s
personal login details; and the customer’s purchased items. This data can be stored in two
types of storage – flat files or databases.
• Flat files are only feasible in very low to low volume websites as flat files have 3 inherent
weaknesses:
1) The inability to efficiently control access by users to the data
INTRODUCTION:
2) The inability to index the data. This makes it necessary to potentially read ALL the data
sequentially. This is a major problem if there are a lot of records in the flat file because the
time required to read the flat file is proportionate to the number of records in the flat file.
3) The inefficient storage of the data. In most cases, the data would not be encrypted or
compressed as this would exacerbate the problem no. 2 above
• The alternative which is, in my opinion, the only feasible method, is to store the data in a
database. One of the most prevalent databases in use is MySQL.
• Data that is stored in a database can easily be indexed, managed and stored efficiently.
Besides that, most databases also provide a suite of accompanying utilities that allow the
database administrator to maintain the database – for example, backup and restore, etc.
PHP MYSQL DATABSE:
• With PHP, you can connect to and manipulate databases.
• MySQL is the most popular database system used with PHP.
What is MySQL?
 MySQL is a database system used on the web
 MySQL is a database system that runs on a server
 MySQL is ideal for both small and large applications
 MySQL is very fast, reliable, and easy to use
 MySQL uses standard SQL
 MySQL compiles on a number of platforms
 MySQL is developed, distributed, and supported by Oracle Corporation
PHP MYSQL DATABSE:
• The data in a MySQL database are stored in tables. A table is a collection of related data,
and it consists of columns and rows.
• Databases are useful for storing information categorically. A company may have a database
with the following tables:
 Employees
 Products
 Customers
 Orders
PHP CONNECT TO MYSQL:
• PHP 5 and later can work with a MySQL database using:
1) MySQLi extension (the "i" stands for improved)
2) PDO (PHP Data Objects)
• Earlier versions of PHP used the MySQL extension. However, this extension was
deprecated in 2012.
• Whould we Use MySQLi or PDO?
 Both MySQLi and PDO have their advantages:
1) PDO will work on 12 different database systems, where as MySQLi will only work with
MySQL databases.
PHP CONNECT TO MYSQL:
2) So, if you have to switch your project to use another database, PDO makes the process
easy. You only have to change the connection string and a few queries. With MySQLi, you
will need to rewrite the entire code - queries included.
3) Both are object-oriented, but MySQLi also offers a procedural API.
4) Both support Prepared Statements. Prepared Statements protect from SQL injection, and
are very important for web application security.
PDO (PHP Data Objects) :
• PDO Installation:
For installation details, go to: http://php.net/manual/en/pdo.installation.php
PDO (PHP Data Objects) :
• Notice that in the PDO example above we have also specified a database (myDB). PDO
require a valid database to connect to. If no database is specified, an exception is thrown.
• A great benefit of PDO is that it has an exception class to handle any problems that may
occur in our database queries. If an exception is thrown within the try{ } block, the script
stops executing and flows directly to the first catch(){ } block.
• Close the Connection:
$conn = null;
PDO (PHP Data Objects) :
• The following PDO example create a database named "myDBPDO":
PDO (PHP Data Objects) :
• A great benefit of PDO is that it has exception class to handle any problems that may occur
in our database queries. If an exception is thrown within the try{ } block, the script stops
executing and flows directly to the first catch(){ } block. In the catch block above we echo
the SQL statement and the generated error message.
• Create a MySQL Table Using PDO:
• The CREATE TABLE statement is used to create a table in MySQL.
• We will create a table named "MyGuests", with five columns: "id", "firstname", "lastname",
"email" and "reg_date"
PDO (PHP Data Objects) :
• The data type specifies what type of data the column can hold. For a complete reference of
all the available data types, go to our Data Types reference.
• After the data type, you can specify other optional attributes for each column:
1) NOT NULL - Each row must contain a value for that column, null values are not allowed
PDO (PHP Data Objects) :
2) DEFAULT value - Set a default value that is added when no other value is passed
3) UNSIGNED - Used for number types, limits the stored data to positive numbers and zero
4) AUTO INCREMENT - MySQL automatically increases the value of the field by 1 each
time a new record is added
5) PRIMARY KEY - Used to uniquely identify the rows in a table. The column with
PRIMARY KEY setting is often an ID number, and is often used with
AUTO_INCREMENT
PDO (PHP Data Objects) :
Insert Data Into MySQL Using PDO:
•After a database and a table have been created, we can start adding data in them.
•Here are some syntax rules to follow:
1)The SQL query must be quoted in PHP
2)String values inside the SQL query must be quoted
3)Numeric values must not be quoted
4)The word NULL must not be quoted
•The INSERT INTO statement is used to add new records to a MySQL table:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
PDO (PHP Data Objects) :
Select Data Into MySQL Using PDO:
•The SELECT statement is used to select data from one or more tables:
SELECT column_name(s) FROM table_name
•or we can use the * character to select ALL columns from a table:
SELECT * FROM table_name
Delete Data Into MySQL Using PDO:
•DELETE FROM table_name WHERE some_column = some_value
PDO (PHP Data Objects) :
Update Data Into MySQL Using PDO:
•The UPDATE statement is used to update existing records in a table:
•UPDATE table_name SET column1=value, column2=value2,...
WHERE some_column=some_value
•Notice the WHERE clause in the UPDATE syntax: The WHERE clause specifies which record
or records that should be updated. If you omit the WHERE clause, all records will be updated!
EXAMPLE:
Insert Data:
EXAMPLE:
Select Data:
php databse handling
OUTPUT:.

More Related Content

PPTX
Db forensics for sql rally
Paresh Motiwala, PMP®
 
PDF
2011 06-sq lite-forensics
viaForensics
 
PDF
Reviewing SQL Concepts
Hitesh Mohapatra
 
PPTX
Android SQLite Database Forensics
forensicEmailAnalysis
 
PPTX
SQLite forensics - Free Lists, unallocated space, carving
Dmitry Kirillin
 
PDF
Advanced database protocols
Hitesh Mohapatra
 
PPT
ADO CONTROLS - Database usage
Muralidharan Radhakrishnan
 
Db forensics for sql rally
Paresh Motiwala, PMP®
 
2011 06-sq lite-forensics
viaForensics
 
Reviewing SQL Concepts
Hitesh Mohapatra
 
Android SQLite Database Forensics
forensicEmailAnalysis
 
SQLite forensics - Free Lists, unallocated space, carving
Dmitry Kirillin
 
Advanced database protocols
Hitesh Mohapatra
 
ADO CONTROLS - Database usage
Muralidharan Radhakrishnan
 

What's hot (20)

PPT
ado.net
ZAIYAUL HAQUE
 
PPT
Sql Server Basics
rainynovember12
 
PPT
No sql or Not only SQL
Ajay Jha
 
PPT
Session x(ado.net)
Shrijan Tiwari
 
ODP
ppt on open office.org
Deepansh Goel
 
PPT
Data Connection using ADO DC
Purbanjali Das
 
PPTX
Slides from the NASIG 2018 Preconference
Terry Reese
 
PPTX
Orcid auto-update at Crossref
Crossref
 
PDF
Apache Lucene intro - Breizhcamp 2015
Adrien Grand
 
PDF
APA ITU DOI?
Relawan Jurnal Indonesia
 
PDF
CARA MEMBUAT REFERENSI DAN SITASI PADA NASKAH
Relawan Jurnal Indonesia
 
PPTX
FileTable and Semantic Search in SQL Server 2012
Michael Rys
 
PDF
ADO.NET difference faqs compiled- 1
Umar Ali
 
PPTX
SPSS: File Managment
DataminingTools Inc
 
PDF
WEB PROGRAMMING USING ASP.NET
DhruvVekariya3
 
PPT
Inb343 week2 sql server intro
Fredlive503
 
PPTX
Introduction to SQL
MLG College of Learning, Inc
 
PPTX
Working with the MarcEditor
Terry Reese
 
PDF
Euclid Data Model 101 - Episode 01: Overview
euc-dm-test
 
DOCX
Convert language latin1 to utf8 on mysql
Vasudeva Rao
 
ado.net
ZAIYAUL HAQUE
 
Sql Server Basics
rainynovember12
 
No sql or Not only SQL
Ajay Jha
 
Session x(ado.net)
Shrijan Tiwari
 
ppt on open office.org
Deepansh Goel
 
Data Connection using ADO DC
Purbanjali Das
 
Slides from the NASIG 2018 Preconference
Terry Reese
 
Orcid auto-update at Crossref
Crossref
 
Apache Lucene intro - Breizhcamp 2015
Adrien Grand
 
CARA MEMBUAT REFERENSI DAN SITASI PADA NASKAH
Relawan Jurnal Indonesia
 
FileTable and Semantic Search in SQL Server 2012
Michael Rys
 
ADO.NET difference faqs compiled- 1
Umar Ali
 
SPSS: File Managment
DataminingTools Inc
 
WEB PROGRAMMING USING ASP.NET
DhruvVekariya3
 
Inb343 week2 sql server intro
Fredlive503
 
Introduction to SQL
MLG College of Learning, Inc
 
Working with the MarcEditor
Terry Reese
 
Euclid Data Model 101 - Episode 01: Overview
euc-dm-test
 
Convert language latin1 to utf8 on mysql
Vasudeva Rao
 
Ad

Similar to php databse handling (20)

PPTX
Data types and variables in php for writing and databse
vishal choudhary
 
PPTX
Learn PHP Lacture2
ADARSH BHATT
 
PPTX
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
PPTX
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
PDF
wee
gapczar
 
PDF
Php summary
Michelle Darling
 
PPTX
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
PPTX
UNIT V (5).pptx
DrDhivyaaCRAssistant
 
PPTX
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PPTX
Php and database functionality
Sayed Ahmed
 
PPTX
PHP and database functionality
Sayed Ahmed
 
PPTX
Php and database functionality
Sayed Ahmed
 
PPT
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
DOCX
100 PHP question and answer
Sandip Murari
 
ODP
Php modul-3
Kristophorus Hadiono
 
PDF
PHP Data Objects
Wez Furlong
 
PPTX
Php talk
Jamil Ramsey
 
PPTX
Connecting to my sql using PHP
Nisa Soomro
 
PPT
Php classes in mumbai
aadi Surve
 
Data types and variables in php for writing and databse
vishal choudhary
 
Learn PHP Lacture2
ADARSH BHATT
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
wee
gapczar
 
Php summary
Michelle Darling
 
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
UNIT V (5).pptx
DrDhivyaaCRAssistant
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
Php and database functionality
Sayed Ahmed
 
PHP and database functionality
Sayed Ahmed
 
Php and database functionality
Sayed Ahmed
 
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
100 PHP question and answer
Sandip Murari
 
PHP Data Objects
Wez Furlong
 
Php talk
Jamil Ramsey
 
Connecting to my sql using PHP
Nisa Soomro
 
Php classes in mumbai
aadi Surve
 
Ad

More from kunj desai (10)

PPTX
OLAP operations
kunj desai
 
PPT
Bottom - Up Parsing
kunj desai
 
PPT
Loaders and Linkers
kunj desai
 
PPT
Binary Search
kunj desai
 
PPTX
Introduction to 8085 microprocessor
kunj desai
 
PPT
Custom Controls in ASP.net
kunj desai
 
PPT
JDBC Connectivity Model
kunj desai
 
PPT
Requirement specification (SRS)
kunj desai
 
PPT
Minimization of DFA
kunj desai
 
PPTX
Concept of constructors
kunj desai
 
OLAP operations
kunj desai
 
Bottom - Up Parsing
kunj desai
 
Loaders and Linkers
kunj desai
 
Binary Search
kunj desai
 
Introduction to 8085 microprocessor
kunj desai
 
Custom Controls in ASP.net
kunj desai
 
JDBC Connectivity Model
kunj desai
 
Requirement specification (SRS)
kunj desai
 
Minimization of DFA
kunj desai
 
Concept of constructors
kunj desai
 

Recently uploaded (20)

PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
PPTX
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPTX
unit 3a.pptx material management. Chapter of operational management
atisht0104
 
PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Information Retrieval and Extraction - Module 7
premSankar19
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
Ppt for engineering students application on field effect
lakshmi.ec
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
unit 3a.pptx material management. Chapter of operational management
atisht0104
 
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 

php databse handling

  • 1. PHP Database Handling • Name: Kunj Desai • Enrollment : 140950107022 • Branch: CSE-A • Year: 2017
  • 2. INTRODUCTION: • Most interactive websites nowadays require data to be presented dynamically and interactively based on input from the user. For example, a customer may need to log into a retail website to check his purchasing history. In this instance, the website would have stored two types of data in order for the customer to perform the check – the customer’s personal login details; and the customer’s purchased items. This data can be stored in two types of storage – flat files or databases. • Flat files are only feasible in very low to low volume websites as flat files have 3 inherent weaknesses: 1) The inability to efficiently control access by users to the data
  • 3. INTRODUCTION: 2) The inability to index the data. This makes it necessary to potentially read ALL the data sequentially. This is a major problem if there are a lot of records in the flat file because the time required to read the flat file is proportionate to the number of records in the flat file. 3) The inefficient storage of the data. In most cases, the data would not be encrypted or compressed as this would exacerbate the problem no. 2 above • The alternative which is, in my opinion, the only feasible method, is to store the data in a database. One of the most prevalent databases in use is MySQL. • Data that is stored in a database can easily be indexed, managed and stored efficiently. Besides that, most databases also provide a suite of accompanying utilities that allow the database administrator to maintain the database – for example, backup and restore, etc.
  • 4. PHP MYSQL DATABSE: • With PHP, you can connect to and manipulate databases. • MySQL is the most popular database system used with PHP. What is MySQL?  MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications  MySQL is very fast, reliable, and easy to use  MySQL uses standard SQL  MySQL compiles on a number of platforms  MySQL is developed, distributed, and supported by Oracle Corporation
  • 5. PHP MYSQL DATABSE: • The data in a MySQL database are stored in tables. A table is a collection of related data, and it consists of columns and rows. • Databases are useful for storing information categorically. A company may have a database with the following tables:  Employees  Products  Customers  Orders
  • 6. PHP CONNECT TO MYSQL: • PHP 5 and later can work with a MySQL database using: 1) MySQLi extension (the "i" stands for improved) 2) PDO (PHP Data Objects) • Earlier versions of PHP used the MySQL extension. However, this extension was deprecated in 2012. • Whould we Use MySQLi or PDO?  Both MySQLi and PDO have their advantages: 1) PDO will work on 12 different database systems, where as MySQLi will only work with MySQL databases.
  • 7. PHP CONNECT TO MYSQL: 2) So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included. 3) Both are object-oriented, but MySQLi also offers a procedural API. 4) Both support Prepared Statements. Prepared Statements protect from SQL injection, and are very important for web application security.
  • 8. PDO (PHP Data Objects) : • PDO Installation: For installation details, go to: http://php.net/manual/en/pdo.installation.php
  • 9. PDO (PHP Data Objects) : • Notice that in the PDO example above we have also specified a database (myDB). PDO require a valid database to connect to. If no database is specified, an exception is thrown. • A great benefit of PDO is that it has an exception class to handle any problems that may occur in our database queries. If an exception is thrown within the try{ } block, the script stops executing and flows directly to the first catch(){ } block. • Close the Connection: $conn = null;
  • 10. PDO (PHP Data Objects) : • The following PDO example create a database named "myDBPDO":
  • 11. PDO (PHP Data Objects) : • A great benefit of PDO is that it has exception class to handle any problems that may occur in our database queries. If an exception is thrown within the try{ } block, the script stops executing and flows directly to the first catch(){ } block. In the catch block above we echo the SQL statement and the generated error message. • Create a MySQL Table Using PDO: • The CREATE TABLE statement is used to create a table in MySQL. • We will create a table named "MyGuests", with five columns: "id", "firstname", "lastname", "email" and "reg_date"
  • 12. PDO (PHP Data Objects) : • The data type specifies what type of data the column can hold. For a complete reference of all the available data types, go to our Data Types reference. • After the data type, you can specify other optional attributes for each column: 1) NOT NULL - Each row must contain a value for that column, null values are not allowed
  • 13. PDO (PHP Data Objects) : 2) DEFAULT value - Set a default value that is added when no other value is passed 3) UNSIGNED - Used for number types, limits the stored data to positive numbers and zero 4) AUTO INCREMENT - MySQL automatically increases the value of the field by 1 each time a new record is added 5) PRIMARY KEY - Used to uniquely identify the rows in a table. The column with PRIMARY KEY setting is often an ID number, and is often used with AUTO_INCREMENT
  • 14. PDO (PHP Data Objects) : Insert Data Into MySQL Using PDO: •After a database and a table have been created, we can start adding data in them. •Here are some syntax rules to follow: 1)The SQL query must be quoted in PHP 2)String values inside the SQL query must be quoted 3)Numeric values must not be quoted 4)The word NULL must not be quoted •The INSERT INTO statement is used to add new records to a MySQL table: INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
  • 15. PDO (PHP Data Objects) : Select Data Into MySQL Using PDO: •The SELECT statement is used to select data from one or more tables: SELECT column_name(s) FROM table_name •or we can use the * character to select ALL columns from a table: SELECT * FROM table_name Delete Data Into MySQL Using PDO: •DELETE FROM table_name WHERE some_column = some_value
  • 16. PDO (PHP Data Objects) : Update Data Into MySQL Using PDO: •The UPDATE statement is used to update existing records in a table: •UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value •Notice the WHERE clause in the UPDATE syntax: The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!