SlideShare a Scribd company logo
1 of 35
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.
   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

More Related Content

What's hot (19)

Intro to T-SQL – 2nd session
Intro to T-SQL – 2nd sessionIntro to T-SQL – 2nd session
Intro to T-SQL – 2nd session
 
Introduction to mysql part 1
Introduction to mysql part 1Introduction to mysql part 1
Introduction to mysql part 1
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5SQL interview questions jeetendra mandal - part 5
SQL interview questions jeetendra mandal - part 5
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
 
Sql
SqlSql
Sql
 
SQL interview questions by Jeetendra Mandal - part 2
SQL interview questions by Jeetendra Mandal - part 2SQL interview questions by Jeetendra Mandal - part 2
SQL interview questions by Jeetendra Mandal - part 2
 
Sql a practical introduction
Sql   a practical introductionSql   a practical introduction
Sql a practical introduction
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
DBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCLDBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCL
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
SQL commands
SQL commandsSQL commands
SQL commands
 
12 SQL
12 SQL12 SQL
12 SQL
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
lovely
lovelylovely
lovely
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 

Viewers also liked

Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style SheetsJerome Locson
 
Online Presence & Blogging 101
Online Presence & Blogging 101Online Presence & Blogging 101
Online Presence & Blogging 101Jerome Locson
 
Map your precinct tutorial
Map your precinct tutorialMap your precinct tutorial
Map your precinct tutorialJerome Locson
 
Basic software
Basic software Basic software
Basic software Muuluu
 
Lecture 3
Lecture 3Lecture 3
Lecture 3Muuluu
 

Viewers also liked (6)

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

Similar to Database Basics and MySQL

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. .
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
2nd chapter dbms.pptx
2nd chapter dbms.pptx2nd chapter dbms.pptx
2nd chapter dbms.pptx
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
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
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
Sql server
Sql serverSql server
Sql server
 
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
 
Module02
Module02Module02
Module02
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
4.Database Management System.pdf
4.Database Management System.pdf4.Database Management System.pdf
4.Database Management System.pdf
 
Adbms
AdbmsAdbms
Adbms
 
Rise of NewSQL
Rise of NewSQLRise of NewSQL
Rise of NewSQL
 
SQL_NOTES.pdf
SQL_NOTES.pdfSQL_NOTES.pdf
SQL_NOTES.pdf
 
Relational Database Management System part II
Relational Database Management System part IIRelational Database Management System part II
Relational Database Management System part II
 
Sql basics 2
Sql basics   2Sql basics   2
Sql basics 2
 
Mysql
MysqlMysql
Mysql
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An Introduction
 

Recently uploaded

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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.
  • 19.
  • 20.
  • 21.
  • 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