SlideShare a Scribd company logo
PHP MySQLPHP MySQL
Chapter 09
MOHAMAD RAHIMI MOHAMAD
ROSMAN
PHP MySQL IntroductionPHP MySQL Introduction
MySQL is the most popular open source
database server.
The free MySQL Database is very often
used with PHP.
Before you can access and work with data
in a database, you must create a
connection to the database.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
PHP MySQL IntroductionPHP MySQL Introduction
A database defines a structure for storing
information.
In a database, there are tables. Just like HTML
tables, database tables contain rows, columns,
and cells.
Databases are useful when storing information
categorically. A company may have a database
with the following tables: "Employees",
"Products", "Customers" and "Orders".
MOHAMAD RAHIMI MOHAMAD
ROSMAN
PHP MySQL Connect to a DatabasePHP MySQL Connect to a Database
In PHP, this is done with the
mysql_connect() function.
Syntax
mysql_connect(servername,username,password)
;
mysql_connect($dbHost,$dbUser,$dbPass)or die(mysql_error());
mysql_select_db($dbName);
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Include databaseInclude database
To prevent
frequent
access to
database and
shorten the
code, we
should use
include()
within all the
files
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Closing a ConnectionClosing a Connection
The connection will be closed as soon as the
script ends. To close the connection before, use
the mysql_close() function.
<?php
$con = mysql_connect("localhost",“root",“is221");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($con);
?>
MOHAMAD RAHIMI MOHAMAD
ROSMAN
QueriesQueries
A query is a question or a request.
With MySQL, we can query a database
for specific information and have a
recordset returned.
Look at the following query:
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Data TypesData Types
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Creating databaseCreating database
Open PHPMyAdmin
Create new database name “php”
Create new table name “user” (5 fields)
Insert following fields
◦ id (bigint, auto increment)
◦ Nama (text)
◦ Ic (text)
◦ Username (text)
◦ Password (text)
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Connecting to the databaseConnecting to the database
 Create a new text document, name it index.php
 Insert the following code
<html><body>
<?php
mysql_connect(“localhost”,”root”,””)or die(mysql_error());
mysql_select_db(“php”);
?>
</body></html>
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Insert Data From a Form Into a DatabaseInsert Data From a Form Into a Database
Now we will create an HTML form that can be
used to add new records to the "Person"
table.
Here is the HTML form:
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Step 1: Create HTML FormStep 1: Create HTML Form
MOHAMAD RAHIMI MOHAMAD
ROSMAN
When a user clicks the submit button in the
HTML form in the example above, the form data
is sent to "insert.php".
The "insert.php" file connects to a database, and
retrieves the values from the form with the PHP
$_POST variables.
Then, the mysql_query() function executes the
INSERT INTO statement, and a new record will
be added to the database table.
Below is the code in the "insert.php" page:
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Insert.phpInsert.php
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Select Data From a Database TableSelect Data From a Database Table
The SELECT statement is used to select
data from a database.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The WHERE clauseThe WHERE clause
To select only data that matches a specific
criteria, add a WHERE clause to the
SELECT statement.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
OperatorOperator
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The ORDER BY KeywordThe ORDER BY Keyword
The ORDER BY keyword is used to sort
the data in a recordset
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
$result = mysql_query("SELECT * FROM user ORDER BY
nama");
$result = mysql_query("SELECT * FROM user ORDER BY
username");
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Sort Ascending or DescendingSort Ascending or Descending
If you use the ORDER BY keyword, the
sort-order of the recordset is ascending by
default (1 before 9 and "a" before "p").
Use the DESC keyword to specify a
descending sort-order (9 before 1 and "p"
before "a"):
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Update Data In a DatabaseUpdate Data In a Database
The UPDATE statement is used to
modify data in a database table
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
mysql_query("UPDATE user SET username= ‘user‘ WHERE ic =
‘1'");
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Delete Data In a DatabaseDelete Data In a Database
The DELETE FROM statement is used to
delete records from a database table.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
mysql_query("DELETE FROM user WHERE ic=‘1'");
MOHAMAD RAHIMI MOHAMAD
ROSMAN
~…The end …~~…The end …~
Thank You Very Much!!
For further questions, comments & suggestion, contact me at:
MOHAMAD RAHIMI BIN MOHAMAD ROSMAN
09-976 2275 / 019-9891306
rahimi.rosman@yahoo.com
http://rahimi.official.ws
http://is110.official.ws
MOHAMAD RAHIMI MOHAMAD
ROSMAN

More Related Content

Similar to Chapter 09 php my sql (20)

harry presentation
harry presentationharry presentation
harry presentation
thembhani mapengo
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
Ahmed Swilam
 
Mysql
MysqlMysql
Mysql
Rathan Raj
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
Php workshop L04 database
Php workshop L04 databasePhp workshop L04 database
Php workshop L04 database
Mohammad Tahsin Alshalabi
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
My_sql_with_php
My_sql_with_phpMy_sql_with_php
My_sql_with_php
Ishaq Shinwari
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Php basics
Php basicsPhp basics
Php basics
Egerton University
 
Pdo – php database extension-Phpgurukul
Pdo – php database extension-PhpgurukulPdo – php database extension-Phpgurukul
Pdo – php database extension-Phpgurukul
PHPGurukul Blog
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
Firdaus Adib
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training Presentations
Srinivas Mutyala
 
PHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHPPHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHP
Vibrant Technologies & Computers
 
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).pptLect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 
Chapter 08 php advance
Chapter 08   php advanceChapter 08   php advance
Chapter 08 php advance
Dhani Ahmad
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
Vidya Topa Institute of Professional Studies
 
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Database management system by Neeraj Bhandari ( Surkhet.Nepal )Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Neeraj Bhandari
 
Big Data: SQL on Hadoop from IBM
Big Data:  SQL on Hadoop from IBM Big Data:  SQL on Hadoop from IBM
Big Data: SQL on Hadoop from IBM
Cynthia Saracco
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
Ahmed Swilam
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Pdo – php database extension-Phpgurukul
Pdo – php database extension-PhpgurukulPdo – php database extension-Phpgurukul
Pdo – php database extension-Phpgurukul
PHPGurukul Blog
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
Firdaus Adib
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training Presentations
Srinivas Mutyala
 
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).pptLect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 
Chapter 08 php advance
Chapter 08   php advanceChapter 08   php advance
Chapter 08 php advance
Dhani Ahmad
 
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Database management system by Neeraj Bhandari ( Surkhet.Nepal )Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Database management system by Neeraj Bhandari ( Surkhet.Nepal )
Neeraj Bhandari
 
Big Data: SQL on Hadoop from IBM
Big Data:  SQL on Hadoop from IBM Big Data:  SQL on Hadoop from IBM
Big Data: SQL on Hadoop from IBM
Cynthia Saracco
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 

More from Dhani Ahmad (20)

Strategic planning
Strategic planningStrategic planning
Strategic planning
Dhani Ahmad
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planning
Dhani Ahmad
 
Opportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysisOpportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysis
Dhani Ahmad
 
Information system
Information systemInformation system
Information system
Dhani Ahmad
 
Information resource management
Information resource managementInformation resource management
Information resource management
Dhani Ahmad
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and records
Dhani Ahmad
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behavior
Dhani Ahmad
 
Islamic information management
Islamic information managementIslamic information management
Islamic information management
Dhani Ahmad
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islam
Dhani Ahmad
 
The need for security
The need for securityThe need for security
The need for security
Dhani Ahmad
 
The information security audit
The information security auditThe information security audit
The information security audit
Dhani Ahmad
 
Security technologies
Security technologiesSecurity technologies
Security technologies
Dhani Ahmad
 
Security policy
Security policySecurity policy
Security policy
Dhani Ahmad
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnel
Dhani Ahmad
 
Secure
SecureSecure
Secure
Dhani Ahmad
 
Risk management ii
Risk management iiRisk management ii
Risk management ii
Dhani Ahmad
 
Risk management i
Risk management iRisk management i
Risk management i
Dhani Ahmad
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care it
Dhani Ahmad
 
Physical security
Physical securityPhysical security
Physical security
Dhani Ahmad
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issues
Dhani Ahmad
 
Strategic planning
Strategic planningStrategic planning
Strategic planning
Dhani Ahmad
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planning
Dhani Ahmad
 
Opportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysisOpportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysis
Dhani Ahmad
 
Information system
Information systemInformation system
Information system
Dhani Ahmad
 
Information resource management
Information resource managementInformation resource management
Information resource management
Dhani Ahmad
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and records
Dhani Ahmad
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behavior
Dhani Ahmad
 
Islamic information management
Islamic information managementIslamic information management
Islamic information management
Dhani Ahmad
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islam
Dhani Ahmad
 
The need for security
The need for securityThe need for security
The need for security
Dhani Ahmad
 
The information security audit
The information security auditThe information security audit
The information security audit
Dhani Ahmad
 
Security technologies
Security technologiesSecurity technologies
Security technologies
Dhani Ahmad
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnel
Dhani Ahmad
 
Risk management ii
Risk management iiRisk management ii
Risk management ii
Dhani Ahmad
 
Risk management i
Risk management iRisk management i
Risk management i
Dhani Ahmad
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care it
Dhani Ahmad
 
Physical security
Physical securityPhysical security
Physical security
Dhani Ahmad
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issues
Dhani Ahmad
 
Ad

Recently uploaded (20)

语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
JunZhao68
 
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptxArtificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
AbhijitPal87
 
Alcoholic liver disease slides presentation new.pptx
Alcoholic liver disease slides presentation new.pptxAlcoholic liver disease slides presentation new.pptx
Alcoholic liver disease slides presentation new.pptx
DrShashank7
 
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
Taqyea
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptxMulti-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
VikashVats1
 
GROUP 7 CASE STUDY Real Life Incident.pptx
GROUP 7 CASE STUDY Real Life Incident.pptxGROUP 7 CASE STUDY Real Life Incident.pptx
GROUP 7 CASE STUDY Real Life Incident.pptx
mardoglenn21
 
Internal Architecture of Database Management Systems
Internal Architecture of Database Management SystemsInternal Architecture of Database Management Systems
Internal Architecture of Database Management Systems
M Munim
 
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Designer
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost  Data Protection People.pdfGDPR Audit - GDPR gap analysis cost  Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
Data Protection People
 
Math arihant handbook.pdf all formula is here
Math arihant handbook.pdf all formula is hereMath arihant handbook.pdf all formula is here
Math arihant handbook.pdf all formula is here
rdarshankumar84
 
time_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptxtime_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptx
stefanopinto1113
 
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
Human body make Structure analysis the part of the human
Human body make Structure analysis the part of the humanHuman body make Structure analysis the part of the human
Human body make Structure analysis the part of the human
ankit392215
 
llm lecture 4 stanford blah blah blah blah
llm lecture 4 stanford blah blah blah blahllm lecture 4 stanford blah blah blah blah
llm lecture 4 stanford blah blah blah blah
saud140081
 
Chapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I willChapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I will
SotheaPheng
 
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docxGeospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
sofiawilliams5966
 
Tableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdfTableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdf
elinavihriala
 
语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
语法专题3-状语从句.pdf 英语语法基础部分,涉及到状语从句部分的内容来米爱上
JunZhao68
 
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptxArtificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
AbhijitPal87
 
Alcoholic liver disease slides presentation new.pptx
Alcoholic liver disease slides presentation new.pptxAlcoholic liver disease slides presentation new.pptx
Alcoholic liver disease slides presentation new.pptx
DrShashank7
 
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
Taqyea
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptxMulti-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
Multi-Agent-Solution-Architecture-for-Unified-Loan-Platform.pptx
VikashVats1
 
GROUP 7 CASE STUDY Real Life Incident.pptx
GROUP 7 CASE STUDY Real Life Incident.pptxGROUP 7 CASE STUDY Real Life Incident.pptx
GROUP 7 CASE STUDY Real Life Incident.pptx
mardoglenn21
 
Internal Architecture of Database Management Systems
Internal Architecture of Database Management SystemsInternal Architecture of Database Management Systems
Internal Architecture of Database Management Systems
M Munim
 
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Glary Utilities Pro 5.157.0.183 Crack + Key Download [Latest]
Designer
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost  Data Protection People.pdfGDPR Audit - GDPR gap analysis cost  Data Protection People.pdf
GDPR Audit - GDPR gap analysis cost Data Protection People.pdf
Data Protection People
 
Math arihant handbook.pdf all formula is here
Math arihant handbook.pdf all formula is hereMath arihant handbook.pdf all formula is here
Math arihant handbook.pdf all formula is here
rdarshankumar84
 
time_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptxtime_series_forecasting_constructor_uni.pptx
time_series_forecasting_constructor_uni.pptx
stefanopinto1113
 
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
Human body make Structure analysis the part of the human
Human body make Structure analysis the part of the humanHuman body make Structure analysis the part of the human
Human body make Structure analysis the part of the human
ankit392215
 
llm lecture 4 stanford blah blah blah blah
llm lecture 4 stanford blah blah blah blahllm lecture 4 stanford blah blah blah blah
llm lecture 4 stanford blah blah blah blah
saud140081
 
Chapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I willChapter 5.1.pptxsertj you can get it done before the election and I will
Chapter 5.1.pptxsertj you can get it done before the election and I will
SotheaPheng
 
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docxGeospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
Geospatial Data_ Unlocking the Power for Smarter Urban Planning.docx
sofiawilliams5966
 
Tableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdfTableau Finland User Group June 2025.pdf
Tableau Finland User Group June 2025.pdf
elinavihriala
 
Ad

Chapter 09 php my sql

  • 1. PHP MySQLPHP MySQL Chapter 09 MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 2. PHP MySQL IntroductionPHP MySQL Introduction MySQL is the most popular open source database server. The free MySQL Database is very often used with PHP. Before you can access and work with data in a database, you must create a connection to the database. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 3. PHP MySQL IntroductionPHP MySQL Introduction A database defines a structure for storing information. In a database, there are tables. Just like HTML tables, database tables contain rows, columns, and cells. Databases are useful when storing information categorically. A company may have a database with the following tables: "Employees", "Products", "Customers" and "Orders". MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 4. PHP MySQL Connect to a DatabasePHP MySQL Connect to a Database In PHP, this is done with the mysql_connect() function. Syntax mysql_connect(servername,username,password) ; mysql_connect($dbHost,$dbUser,$dbPass)or die(mysql_error()); mysql_select_db($dbName); MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 5. Include databaseInclude database To prevent frequent access to database and shorten the code, we should use include() within all the files MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 6. Closing a ConnectionClosing a Connection The connection will be closed as soon as the script ends. To close the connection before, use the mysql_close() function. <?php $con = mysql_connect("localhost",“root",“is221"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_close($con); ?> MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 7. QueriesQueries A query is a question or a request. With MySQL, we can query a database for specific information and have a recordset returned. Look at the following query: MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 8. Data TypesData Types MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 9. Creating databaseCreating database Open PHPMyAdmin Create new database name “php” Create new table name “user” (5 fields) Insert following fields ◦ id (bigint, auto increment) ◦ Nama (text) ◦ Ic (text) ◦ Username (text) ◦ Password (text) MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 10. Connecting to the databaseConnecting to the database  Create a new text document, name it index.php  Insert the following code <html><body> <?php mysql_connect(“localhost”,”root”,””)or die(mysql_error()); mysql_select_db(“php”); ?> </body></html> MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 11. Insert Data From a Form Into a DatabaseInsert Data From a Form Into a Database Now we will create an HTML form that can be used to add new records to the "Person" table. Here is the HTML form: MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 12. Step 1: Create HTML FormStep 1: Create HTML Form MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 13. When a user clicks the submit button in the HTML form in the example above, the form data is sent to "insert.php". The "insert.php" file connects to a database, and retrieves the values from the form with the PHP $_POST variables. Then, the mysql_query() function executes the INSERT INTO statement, and a new record will be added to the database table. Below is the code in the "insert.php" page: MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 15. Select Data From a Database TableSelect Data From a Database Table The SELECT statement is used to select data from a database. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 18. The WHERE clauseThe WHERE clause To select only data that matches a specific criteria, add a WHERE clause to the SELECT statement. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 21. The ORDER BY KeywordThe ORDER BY Keyword The ORDER BY keyword is used to sort the data in a recordset MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 22. ExampleExample $result = mysql_query("SELECT * FROM user ORDER BY nama"); $result = mysql_query("SELECT * FROM user ORDER BY username"); MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 23. Sort Ascending or DescendingSort Ascending or Descending If you use the ORDER BY keyword, the sort-order of the recordset is ascending by default (1 before 9 and "a" before "p"). Use the DESC keyword to specify a descending sort-order (9 before 1 and "p" before "a"): MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 24. Update Data In a DatabaseUpdate Data In a Database The UPDATE statement is used to modify data in a database table MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 25. ExampleExample mysql_query("UPDATE user SET username= ‘user‘ WHERE ic = ‘1'"); MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 26. Delete Data In a DatabaseDelete Data In a Database The DELETE FROM statement is used to delete records from a database table. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 27. ExampleExample mysql_query("DELETE FROM user WHERE ic=‘1'"); MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 28. ~…The end …~~…The end …~ Thank You Very Much!! For further questions, comments & suggestion, contact me at: MOHAMAD RAHIMI BIN MOHAMAD ROSMAN 09-976 2275 / 019-9891306 [email protected] http://rahimi.official.ws http://is110.official.ws MOHAMAD RAHIMI MOHAMAD ROSMAN