SlideShare a Scribd company logo
1 of 28
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

Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Pdo – php database extension-Phpgurukul
Pdo – php database extension-PhpgurukulPdo – php database extension-Phpgurukul
Pdo – php database extension-PhpgurukulPHPGurukul 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 IIFirdaus Adib
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsSrinivas Mutyala
 
Chapter 08 php advance
Chapter 08   php advanceChapter 08   php advance
Chapter 08 php advanceDhani 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 MySqlkamal 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.docxmoirarandell
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbaiaadi Surve
 

Similar to Chapter 09 php my sql (20)

harry presentation
harry presentationharry presentation
harry presentation
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Mysql
MysqlMysql
Mysql
 
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
 
Php workshop L04 database
Php workshop L04 databasePhp workshop L04 database
Php workshop L04 database
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
My_sql_with_php
My_sql_with_phpMy_sql_with_php
My_sql_with_php
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Php basics
Php basicsPhp basics
Php basics
 
Pdo – php database extension-Phpgurukul
Pdo – php database extension-PhpgurukulPdo – php database extension-Phpgurukul
Pdo – php database extension-Phpgurukul
 
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
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training Presentations
 
PHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHPPHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHP
 
Chapter 08 php advance
Chapter 08   php advanceChapter 08   php advance
Chapter 08 php advance
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
 
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 )
 
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
 
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
 
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
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 

More from Dhani Ahmad

Strategic planning
Strategic planningStrategic planning
Strategic planningDhani Ahmad
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planningDhani 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 analysisDhani Ahmad
 
Information system
Information systemInformation system
Information systemDhani Ahmad
 
Information resource management
Information resource managementInformation resource management
Information resource managementDhani Ahmad
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and recordsDhani Ahmad
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behaviorDhani Ahmad
 
Islamic information management
Islamic information managementIslamic information management
Islamic information managementDhani Ahmad
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islamDhani Ahmad
 
The need for security
The need for securityThe need for security
The need for securityDhani Ahmad
 
The information security audit
The information security auditThe information security audit
The information security auditDhani Ahmad
 
Security technologies
Security technologiesSecurity technologies
Security technologiesDhani Ahmad
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnelDhani Ahmad
 
Risk management ii
Risk management iiRisk management ii
Risk management iiDhani Ahmad
 
Risk management i
Risk management iRisk management i
Risk management iDhani Ahmad
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care itDhani Ahmad
 
Physical security
Physical securityPhysical security
Physical securityDhani Ahmad
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issuesDhani Ahmad
 

More from Dhani Ahmad (20)

Strategic planning
Strategic planningStrategic planning
Strategic planning
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planning
 
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
 
Information system
Information systemInformation system
Information system
 
Information resource management
Information resource managementInformation resource management
Information resource management
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and records
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behavior
 
Islamic information management
Islamic information managementIslamic information management
Islamic information management
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islam
 
The need for security
The need for securityThe need for security
The need for security
 
The information security audit
The information security auditThe information security audit
The information security audit
 
Security technologies
Security technologiesSecurity technologies
Security technologies
 
Security policy
Security policySecurity policy
Security policy
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnel
 
Secure
SecureSecure
Secure
 
Risk management ii
Risk management iiRisk management ii
Risk management ii
 
Risk management i
Risk management iRisk management i
Risk management i
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care it
 
Physical security
Physical securityPhysical security
Physical security
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issues
 

Recently uploaded

EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/managementakshesh doshi
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationBoston Institute of Analytics
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 

Recently uploaded (20)

Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/management
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health Classification
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 

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 rahimi.rosman@yahoo.com http://rahimi.official.ws http://is110.official.ws MOHAMAD RAHIMI MOHAMAD ROSMAN