SlideShare a Scribd company logo
1 of 17
MySQL Record Operations
Jamshid Hashimi
Trainer, Cresco Solution
http://www.jamshidhashimi.com
jamshid@netlinks.af
@jamshidhashimi
ajamshidhashimi
Afghanistan Workforce
Development Program
Agenda
• MySQLi Introduction
• mysqli() Overview
• mysqli Methods and Properties
• INSERT, UPDATE & DELETE
• mysqli Prepared Statements
• Inserting, Updating and Deleting Records
• Managing Data
MySQLi Introduction
• MySQLi, often called MySQL Improved, has
several advantages over regular MySQL,
including support for prepared statements
(which helps prevent SQL injection, a common
security issue) and object-oriented code.
MySQLi Introduction
• The mysqli extension has a number of
benefits, the key enhancements over the
mysql extension being:
– Object-oriented interface
– Support for Prepared Statements
– Support for Multiple Statements
– Support for Transactions
– Enhanced debugging capabilities
– Embedded server support
MySQLi Introduction
• mysql_query() – Deprecated!
MySQLi
• mysqli_fetch_assoc (fetch_assoc())
– Fetch a result row as an associative array
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s n", $row["Name”]);
}
MySQLi
• mysqli_fetch_array (fetch_array())
– Fetch a result row as an associative, a numeric
array, or both
– MYSQLI_NUM
– MYSQLI_ASSOC
– MYSQLI_BOTH
/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%sn", $row["Name”]);
MySQLi
• mysqli_fetch_object (fetch_object())
– Returns the current row of a result set as an
object
/* fetch object array */
while ($obj = $result->fetch_object()) {
printf ("%s n", $obj->Name);
}
MySQLi
• Do we need to close the connection?
– Open connections (and similar resources) are
automatically destroyed at the end of script
execution. However, you should still close or free
all connections, result sets and statement handles
as soon as they are no longer required. This will
help return resources to PHP and MySQL faster.
INSERT
• The INSERT INTO statement is used to insert
new records in a table.
• Syntax:
INSERT INTO table_name (column1, column2,
column3,...)
VALUES (value1, value2, value3,...)
UPDATE
• The UPDATE statement is used to modify data
in a table.
• Syntax:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
DELETE
• The DELETE statement is used to delete
records in a table.
• Syntax:
DELETE FROM table_name
WHERE some_column = some_value
Prepared Statements
• Prepared statements provide developers with
the ability to create queries that are more
secure, have better performance, and are
more convenient to write.
Prepared Statements
if($rs = $mysqli->prepare("SELECT first_name FROM actor
WHERE first_name = ?")){
//binding parameteres
$rs->bind_param("s",$name);
$name = "BON";
//Execute it
$rs->execute();
//Bind results
$rs->bind_result($name);
//Fetch records
$rs->fetch();
printf("%s", $name);
$rs->close();
}else{
echo $mysqli->error;
}
$mysqli->close();
Managing Data
DEMO
QUESTIONS?

More Related Content

What's hot

android sqlite
android sqliteandroid sqlite
android sqlite
Deepa Rani
 

What's hot (15)

MySQL HA Solutions (Recopilation)
MySQL HA Solutions (Recopilation)MySQL HA Solutions (Recopilation)
MySQL HA Solutions (Recopilation)
 
MySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in BangaloreMySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in Bangalore
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Alasql fast JavaScript in-memory SQL database
Alasql fast JavaScript in-memory SQL databaseAlasql fast JavaScript in-memory SQL database
Alasql fast JavaScript in-memory SQL database
 
Introduction to php database connectivity
Introduction to php  database connectivityIntroduction to php  database connectivity
Introduction to php database connectivity
 
Sqlite
SqliteSqlite
Sqlite
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 
Fosdem2014 MariaDB CONNECT Storage Engine
Fosdem2014 MariaDB CONNECT Storage EngineFosdem2014 MariaDB CONNECT Storage Engine
Fosdem2014 MariaDB CONNECT Storage Engine
 
Hive jdbc
Hive jdbcHive jdbc
Hive jdbc
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
MariaDB pres at LeMUG
MariaDB pres at LeMUGMariaDB pres at LeMUG
MariaDB pres at LeMUG
 
SQL and NoSQL Better Together in Alasql
SQL and NoSQL Better Together in AlasqlSQL and NoSQL Better Together in Alasql
SQL and NoSQL Better Together in Alasql
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
How to search extracted data
How to search extracted dataHow to search extracted data
How to search extracted data
 

Viewers also liked (9)

Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
 
mySQL and Relational Databases
mySQL and Relational DatabasesmySQL and Relational Databases
mySQL and Relational Databases
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
File organization
File organizationFile organization
File organization
 
File organization 1
File organization 1File organization 1
File organization 1
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and Concepts
 

Similar to MySQL Record Operations

MySQL developing Store Procedure
MySQL developing Store ProcedureMySQL developing Store Procedure
MySQL developing Store Procedure
Marco Tusa
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
Mir Majid
 
MySQL Reference Manual
MySQL Reference ManualMySQL Reference Manual
MySQL Reference Manual
webhostingguy
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 

Similar to MySQL Record Operations (20)

PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
My sql1
My sql1My sql1
My sql1
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
MySQL developing Store Procedure
MySQL developing Store ProcedureMySQL developing Store Procedure
MySQL developing Store Procedure
 
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
 
Mysql
MysqlMysql
Mysql
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Fudcon talk.ppt
Fudcon talk.pptFudcon talk.ppt
Fudcon talk.ppt
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
 
MySQL Reference Manual
MySQL Reference ManualMySQL Reference Manual
MySQL Reference Manual
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 

More from Jamshid Hashimi

CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper Functions
Jamshid Hashimi
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniter
Jamshid Hashimi
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
Jamshid Hashimi
 

More from Jamshid Hashimi (20)

Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1
 
Introduction to C# - Week 0
Introduction to C# - Week 0Introduction to C# - Week 0
Introduction to C# - Week 0
 
RIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyRIST - Research Institute for Science and Technology
RIST - Research Institute for Science and Technology
 
How Coding Can Make Your Life Better
How Coding Can Make Your Life BetterHow Coding Can Make Your Life Better
How Coding Can Make Your Life Better
 
Mobile Vision
Mobile VisionMobile Vision
Mobile Vision
 
Tips for Writing Better Code
Tips for Writing Better CodeTips for Writing Better Code
Tips for Writing Better Code
 
Launch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationLaunch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media Integration
 
Customizing Your Blog 2
Customizing Your Blog 2Customizing Your Blog 2
Customizing Your Blog 2
 
Customizing Your Blog 1
Customizing Your Blog 1Customizing Your Blog 1
Customizing Your Blog 1
 
Introduction to Blogging
Introduction to BloggingIntroduction to Blogging
Introduction to Blogging
 
Introduction to Wordpress
Introduction to WordpressIntroduction to Wordpress
Introduction to Wordpress
 
CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper Functions
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniter
 
CodeIgniter Practice
CodeIgniter PracticeCodeIgniter Practice
CodeIgniter Practice
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 
Exception & Database
Exception & DatabaseException & Database
Exception & Database
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 

Recently uploaded (20)

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

MySQL Record Operations

  • 1. MySQL Record Operations Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com jamshid@netlinks.af @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program
  • 2. Agenda • MySQLi Introduction • mysqli() Overview • mysqli Methods and Properties • INSERT, UPDATE & DELETE • mysqli Prepared Statements • Inserting, Updating and Deleting Records • Managing Data
  • 3. MySQLi Introduction • MySQLi, often called MySQL Improved, has several advantages over regular MySQL, including support for prepared statements (which helps prevent SQL injection, a common security issue) and object-oriented code.
  • 4. MySQLi Introduction • The mysqli extension has a number of benefits, the key enhancements over the mysql extension being: – Object-oriented interface – Support for Prepared Statements – Support for Multiple Statements – Support for Transactions – Enhanced debugging capabilities – Embedded server support
  • 6. MySQLi • mysqli_fetch_assoc (fetch_assoc()) – Fetch a result row as an associative array /* fetch associative array */ while ($row = $result->fetch_assoc()) { printf ("%s n", $row["Name”]); }
  • 7. MySQLi • mysqli_fetch_array (fetch_array()) – Fetch a result row as an associative, a numeric array, or both – MYSQLI_NUM – MYSQLI_ASSOC – MYSQLI_BOTH /* associative array */ $row = $result->fetch_array(MYSQLI_ASSOC); printf ("%sn", $row["Name”]);
  • 8. MySQLi • mysqli_fetch_object (fetch_object()) – Returns the current row of a result set as an object /* fetch object array */ while ($obj = $result->fetch_object()) { printf ("%s n", $obj->Name); }
  • 9. MySQLi • Do we need to close the connection? – Open connections (and similar resources) are automatically destroyed at the end of script execution. However, you should still close or free all connections, result sets and statement handles as soon as they are no longer required. This will help return resources to PHP and MySQL faster.
  • 10. INSERT • The INSERT INTO statement is used to insert new records in a table. • Syntax: INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
  • 11. UPDATE • The UPDATE statement is used to modify data in a table. • Syntax: UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value
  • 12. DELETE • The DELETE statement is used to delete records in a table. • Syntax: DELETE FROM table_name WHERE some_column = some_value
  • 13. Prepared Statements • Prepared statements provide developers with the ability to create queries that are more secure, have better performance, and are more convenient to write.
  • 14. Prepared Statements if($rs = $mysqli->prepare("SELECT first_name FROM actor WHERE first_name = ?")){ //binding parameteres $rs->bind_param("s",$name); $name = "BON"; //Execute it $rs->execute(); //Bind results $rs->bind_result($name); //Fetch records $rs->fetch(); printf("%s", $name); $rs->close(); }else{ echo $mysqli->error; } $mysqli->close();
  • 16. DEMO