SlideShare a Scribd company logo
Creation, Manipulation, and Management




Jerome Locson
Developer, Ariba Tech Solutions
me@jeromelocson.com
   Graduate from ADZU, BSCS
   PhilNITS FE Passer
   GTUG PH, Zamboanga Chapter Community
    Manager
   Technopreneur, Ariba Tech Solutions
   Blog: www.jeromelocson.com
   Relational Database Concept
   Structure Query Language (SQL)
    ◦ DDL, DML and DCL
   Database Normalization
   ACID Property
   Relational Database Management Systems
    (RDBMS), MySQL
   Example of MySQL Queries (PhpMyAdmin)
   SQL Injection Prevention
◦ Used by all major commercial database systems
◦ Very simple model
◦ Query with high-level languages: simple yet
  expressive
◦ Efficient implementations
Schema = structural description of relations in database
Instance = actual contents at given point in time
Database = set of named relations (or tables)
 Each relation has a set of named attributes (or
columns)
 Each tuple (or row) has a value for each attribute
 Each attribute has a type (or domain)
NULL – special value for “unknown” or “undefined”
Key – attribute whose value is unique in each tuple
 Or set of attributes whose combined values are
unique
◦ Used by all major commercial database systems
◦ Very simple model
◦ Query with high-level languages: simple yet
  expressive
◦ Efficient implementations
   Standard/dominant language for accessing
    databases and processing
   Steady improvements in reliability,
    performance and security
   Applicable to many database systems
   It can define a database (DDL)
   It can manipulate database (DML)
   and, can control a database (DCL)
   defining the structure and contents of a
    relational database
   Metadata (data about the data)
   defines the mapping of database to physical
    hardware and devices
   Basic Syntax:
    ◦ Create Table, Alter Table, Drop Table, Create View,
      Create User, etc.
   specifies how queries and updates are to be
    done
   Basic Syntax:
    ◦ Select, Insert, Delete, Update
   involves configuring and controlling the
    database - permission, roles, and referential
    integrity
   Basic Syntax:
    ◦ Grant, Check, Constraint, Primary Key, Foreign Key
   Process of efficiently organizing data in a
    database (1NF-5NF)
   Too: Entity-Relationship Diagram (ERD)
   Goals:
    ◦ eliminating redundant data
    ◦ ensuring data dependencies make sense
   Forms:
    ◦ 1NF (First Normal Form)
    ◦ 2NF (Second Normal Form)
    ◦ 3NF (Third Normal Form)
   First normal form (1NF) sets the very basic
    rules for an organized database:

    ◦ Eliminate duplicative columns from the same table.
    ◦ Create separate tables for each group of related
      data and identify each row with a unique column or
      set of columns (the primary key).
   Second normal form (2NF) further addresses
    the concept of removing duplicative data:

    ◦ Meet all the requirements of the first normal form.
    ◦ Remove subsets of data that apply to multiple rows
      of a table and place them in separate tables.
    ◦ Create relationships between these new tables and
      their predecessors through the use of foreign keys.
   Third normal form (3NF) goes one large step
    further:
    ◦ Meet all the requirements of the second normal
      form.
    ◦ Remove columns that are not dependent upon the
      primary key.
Database Basics and MySQL
Database Basics and MySQL
Database Basics and MySQL
   Stands for atomicity, consistency, isolation,
    durability
   set of properties that guarantee database
    transactions are processed reliably
   Atomicity (atomic)
    ◦ requires that database modifications must follow an
      "all or nothing" rule
    ◦ If one part of the transaction fails, the entire
      transaction fails and the database state is left
      unchanged.
   Consistency
    ◦ ensures that any transaction the database performs
      will take it from one consistent state to another
    ◦ only consistent (valid according to all the rules
      defined) data will be written to the database
    ◦ whatever rows will be affected by the transaction
      will remain consistent with each and every rule
   Isolation
    ◦ no transaction should be able to interfere with
      another transaction at all
    ◦ use a serial model where no two transactions can
      occur on the same data at the same time
   Durability
    ◦ once a transaction has been committed, it will
      remain so
    ◦ every committed transaction is protected against
      power loss/crash/errors and cannot be lost by the
      system and can thus be guaranteed to be
      completed
   RDBMS is the basis for SQL, and for all
    modern database systems like MS SQL Server,
    IBM DB2, Oracle, MySQL, and Microsoft
    Access.
   MySQL database is the world's most popular
    open source database for the Web
   Supports different languages,
       environment, etc.
   www.mysql.com
•   mysql_connect(host, username
    [,password]);
    ◦ Connects to a MySQL server on the specified host
      using the given username and/or password.
      Returns a MySQL link identifier on success, or FALSE
      on failure.
•   mysql_select_db(db_name [,resource])
    ◦ Selects a database from the database server.
•   mysql_query(SQL, resource);
    ◦ Sends the specified SQL query to the database
      specified by the resource identifier. The retrieved data
      are returned by the function as a MySQL result set.
•   mysql_result(result, row [,field]);
    ◦ Returns the contents of one cell from a MySQL result
      set. The field argument can be the field name or the
      field’s offset.
•   mysql_fetch_array(result [,result_type])
    ◦ Fetch a result row as an associative array, a numeric
      array, or both. The result type can take the constants
      MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.
•   mysql_free_result(result)
    ◦ Frees the result set
•   mysql_close(resource)
    ◦ Closes the connection to the database.
   If there is error in the database connection,
    you can terminate the current script by
    using the die function.
   For example:
     $db = mysql_connect("localhost", "root“, “”)
        or die("Could not connect : " .
    mysql_error());

    mysql_select_db("my_database")
       or die("Could not select database");

     $result = mysql_query($query)
        or die("Query failed");
<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user",
mysql_password")
   or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("my_database") or die("Could not select
database");

/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query)                      Loop through each row
   or die("Query failed : " . mysql_error());         of the result set

/* Printing results in HTML */
echo "<table>n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "t<tr>n";
   foreach ($line as $col_value) {               Loop through each
       echo "tt<td>$col_value</td>n";          element in a row
   }
   echo "t</tr>n";
}
/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);
?>
   Using mysql_real_escape_string()
   Using of string replace method for SQL
    keywords like SELECT, INSERT, DELETE and
    UPDATE
Database Basics and MySQL
Ad

More Related Content

What's hot (20)

1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
koolkampus
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Prateek Parimal
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
Oum Saokosal
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
Fundamentals of Database Design
Fundamentals of Database DesignFundamentals of Database Design
Fundamentals of Database Design
Information Technology
 
normaliztion
normaliztionnormaliztion
normaliztion
Ramadhani S. Zuberi
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
Prof.Nilesh Magar
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
Data Flow Diagrams
Data Flow DiagramsData Flow Diagrams
Data Flow Diagrams
Sinhaa Yash
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Data independence
Data independenceData independence
Data independence
Aashima Wadhwa
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
pnp @in
 
Queries
QueriesQueries
Queries
lindy23
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
prabhu rajendran
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
DataminingTools Inc
 

Viewers also liked (6)

Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Jerome Locson
 
Online Presence & Blogging 101
Online Presence & Blogging 101Online Presence & Blogging 101
Online Presence & Blogging 101
Jerome Locson
 
Cs 356 pitch
Cs 356   pitchCs 356   pitch
Cs 356 pitch
Jerome Locson
 
Map your precinct tutorial
Map your precinct tutorialMap your precinct tutorial
Map your precinct tutorial
Jerome Locson
 
Basic software
Basic software Basic software
Basic software
Muuluu
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Muuluu
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Jerome Locson
 
Online Presence & Blogging 101
Online Presence & Blogging 101Online Presence & Blogging 101
Online Presence & Blogging 101
Jerome Locson
 
Map your precinct tutorial
Map your precinct tutorialMap your precinct tutorial
Map your precinct tutorial
Jerome Locson
 
Basic software
Basic software Basic software
Basic software
Muuluu
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Muuluu
 
Ad

Similar to Database Basics and MySQL (20)

Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
MayankSinghRawat6
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
chaitanya149090
 
MySQL Interview Questions and Answers PDF By ScholarHat.pdf
MySQL Interview Questions and Answers PDF By ScholarHat.pdfMySQL Interview Questions and Answers PDF By ScholarHat.pdf
MySQL Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
Eleonora Ciceri
 
2nd chapter dbms.pptx
2nd chapter dbms.pptx2nd chapter dbms.pptx
2nd chapter dbms.pptx
kavitha623544
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
wahidullah mudaser
 
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
kkillams
 
Sql server
Sql serverSql server
Sql server
Puja Gupta
 
Azure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full CourseAzure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full Course
Piyush sachdeva
 
lovely
lovelylovely
lovely
love0323
 
Sql
SqlSql
Sql
YUCHENG HU
 
Structures query language ___PPT (1).pdf
Structures query language ___PPT (1).pdfStructures query language ___PPT (1).pdf
Structures query language ___PPT (1).pdf
tipurple7989
 
Module02
Module02Module02
Module02
Sridhar P
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Lec02_Database System Concepts and Architecture_part1.pptx
Lec02_Database System Concepts and Architecture_part1.pptxLec02_Database System Concepts and Architecture_part1.pptx
Lec02_Database System Concepts and Architecture_part1.pptx
AhmedSalama337512
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
Aditya Kumar Tripathy
 
4.Database Management System.pdf
4.Database Management System.pdf4.Database Management System.pdf
4.Database Management System.pdf
Export Promotion Bureau
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
MayankSinghRawat6
 
MySQL Interview Questions and Answers PDF By ScholarHat.pdf
MySQL Interview Questions and Answers PDF By ScholarHat.pdfMySQL Interview Questions and Answers PDF By ScholarHat.pdf
MySQL Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
2nd chapter dbms.pptx
2nd chapter dbms.pptx2nd chapter dbms.pptx
2nd chapter dbms.pptx
kavitha623544
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
UNIT2-Reference ppt..pptx which weil; be leading tpo the undrsdtanding od thr...
kkillams
 
Azure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full CourseAzure Data Fundamentals DP 900 Full Course
Azure Data Fundamentals DP 900 Full Course
Piyush sachdeva
 
Structures query language ___PPT (1).pdf
Structures query language ___PPT (1).pdfStructures query language ___PPT (1).pdf
Structures query language ___PPT (1).pdf
tipurple7989
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Lec02_Database System Concepts and Architecture_part1.pptx
Lec02_Database System Concepts and Architecture_part1.pptxLec02_Database System Concepts and Architecture_part1.pptx
Lec02_Database System Concepts and Architecture_part1.pptx
AhmedSalama337512
 
Ad

Recently uploaded (20)

Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 

Database Basics and MySQL

  • 1. Creation, Manipulation, and Management Jerome Locson Developer, Ariba Tech Solutions me@jeromelocson.com
  • 2. Graduate from ADZU, BSCS  PhilNITS FE Passer  GTUG PH, Zamboanga Chapter Community Manager  Technopreneur, Ariba Tech Solutions  Blog: www.jeromelocson.com
  • 3. Relational Database Concept  Structure Query Language (SQL) ◦ DDL, DML and DCL  Database Normalization  ACID Property  Relational Database Management Systems (RDBMS), MySQL  Example of MySQL Queries (PhpMyAdmin)  SQL Injection Prevention
  • 4. ◦ Used by all major commercial database systems ◦ Very simple model ◦ Query with high-level languages: simple yet expressive ◦ Efficient implementations
  • 5. Schema = structural description of relations in database Instance = actual contents at given point in time
  • 6. Database = set of named relations (or tables) Each relation has a set of named attributes (or columns) Each tuple (or row) has a value for each attribute Each attribute has a type (or domain)
  • 7. NULL – special value for “unknown” or “undefined”
  • 8. Key – attribute whose value is unique in each tuple Or set of attributes whose combined values are unique
  • 9. ◦ Used by all major commercial database systems ◦ Very simple model ◦ Query with high-level languages: simple yet expressive ◦ Efficient implementations
  • 10. Standard/dominant language for accessing databases and processing  Steady improvements in reliability, performance and security  Applicable to many database systems
  • 11. It can define a database (DDL)  It can manipulate database (DML)  and, can control a database (DCL)
  • 12. defining the structure and contents of a relational database  Metadata (data about the data)  defines the mapping of database to physical hardware and devices  Basic Syntax: ◦ Create Table, Alter Table, Drop Table, Create View, Create User, etc.
  • 13. specifies how queries and updates are to be done  Basic Syntax: ◦ Select, Insert, Delete, Update
  • 14. involves configuring and controlling the database - permission, roles, and referential integrity  Basic Syntax: ◦ Grant, Check, Constraint, Primary Key, Foreign Key
  • 15. Process of efficiently organizing data in a database (1NF-5NF)  Too: Entity-Relationship Diagram (ERD)  Goals: ◦ eliminating redundant data ◦ ensuring data dependencies make sense  Forms: ◦ 1NF (First Normal Form) ◦ 2NF (Second Normal Form) ◦ 3NF (Third Normal Form)
  • 16. First normal form (1NF) sets the very basic rules for an organized database: ◦ Eliminate duplicative columns from the same table. ◦ Create separate tables for each group of related data and identify each row with a unique column or set of columns (the primary key).
  • 17. Second normal form (2NF) further addresses the concept of removing duplicative data: ◦ Meet all the requirements of the first normal form. ◦ Remove subsets of data that apply to multiple rows of a table and place them in separate tables. ◦ Create relationships between these new tables and their predecessors through the use of foreign keys.
  • 18. Third normal form (3NF) goes one large step further: ◦ Meet all the requirements of the second normal form. ◦ Remove columns that are not dependent upon the primary key.
  • 22. Stands for atomicity, consistency, isolation, durability  set of properties that guarantee database transactions are processed reliably
  • 23. Atomicity (atomic) ◦ requires that database modifications must follow an "all or nothing" rule ◦ If one part of the transaction fails, the entire transaction fails and the database state is left unchanged.
  • 24. Consistency ◦ ensures that any transaction the database performs will take it from one consistent state to another ◦ only consistent (valid according to all the rules defined) data will be written to the database ◦ whatever rows will be affected by the transaction will remain consistent with each and every rule
  • 25. Isolation ◦ no transaction should be able to interfere with another transaction at all ◦ use a serial model where no two transactions can occur on the same data at the same time
  • 26. Durability ◦ once a transaction has been committed, it will remain so ◦ every committed transaction is protected against power loss/crash/errors and cannot be lost by the system and can thus be guaranteed to be completed
  • 27. RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.  MySQL database is the world's most popular open source database for the Web  Supports different languages, environment, etc.  www.mysql.com
  • 28. mysql_connect(host, username [,password]); ◦ Connects to a MySQL server on the specified host using the given username and/or password. Returns a MySQL link identifier on success, or FALSE on failure. • mysql_select_db(db_name [,resource]) ◦ Selects a database from the database server.
  • 29. mysql_query(SQL, resource); ◦ Sends the specified SQL query to the database specified by the resource identifier. The retrieved data are returned by the function as a MySQL result set. • mysql_result(result, row [,field]); ◦ Returns the contents of one cell from a MySQL result set. The field argument can be the field name or the field’s offset. • mysql_fetch_array(result [,result_type]) ◦ Fetch a result row as an associative array, a numeric array, or both. The result type can take the constants MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.
  • 30. mysql_free_result(result) ◦ Frees the result set • mysql_close(resource) ◦ Closes the connection to the database.
  • 31. If there is error in the database connection, you can terminate the current script by using the die function.  For example: $db = mysql_connect("localhost", "root“, “”) or die("Could not connect : " . mysql_error()); mysql_select_db("my_database") or die("Could not select database"); $result = mysql_query($query) or die("Query failed");
  • 32. <?php /* Connecting, selecting database */ $link = mysql_connect("mysql_host", "mysql_user", mysql_password") or die("Could not connect : " . mysql_error()); echo "Connected successfully"; mysql_select_db("my_database") or die("Could not select database"); /* Performing SQL query */ $query = "SELECT * FROM my_table"; $result = mysql_query($query) Loop through each row or die("Query failed : " . mysql_error()); of the result set /* Printing results in HTML */ echo "<table>n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "t<tr>n"; foreach ($line as $col_value) { Loop through each echo "tt<td>$col_value</td>n"; element in a row } echo "t</tr>n"; }
  • 33. /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?>
  • 34. Using mysql_real_escape_string()  Using of string replace method for SQL keywords like SELECT, INSERT, DELETE and UPDATE
  翻译: