Chapter 7 - 8: Working With Databases and SQL
Chapter 7 - 8: Working With Databases and SQL
Prepared by:
Ryan B. Azur
PHP – Working with Database and SQL
Key Skills and Concepts
Learn database concepts and Structured Query
Language
Add, edit, delete, and view records using MySQL and
MySQLi databases
Retrieve database records with PHP
Validate and save user input to a database with PHP
Write portable database-driven programs
Database Concepts
Introduction
PHP supports more than fifteen different database
engines, including Microsoft SQL Server, IBM DB2,
PostgreSQL, MySQL, and Oracle. Until PHP 5, this
support was offered through native database
extensions, each with its own functions and features;
however, this made it hard for developers to change
from one database engine to another. PHP 5 rectified
this situation by introducing a common API for
database access: the PHP Data Objects (PDO)
extension, which provides a unified interface to
working with databases and helps developers
manipulate different databases in a consistent manner.
Database Concepts
Brief History
Electronic databases were first used in the 1960s, a
little later than the first application of computers in
businesses.
In 1970, Dr. Edgar F. Codd published an academic paper
on relational databases. His article inspired the
creation of a language to handle database transactions
called Sequel or Structured English Query Language
The word “ English” was later dropped and the
language was standardized to SQL or Structured Query
Language.
SQL, is a way of giving the computer instructions on
how to handle large volumes of data.
Database Concepts
SQL
SQL is an abbreviation for Structured Query Language.
It is generally pronounced “Sequel”
SQL is a unified language for... defining, querying,
modifying, and controlling the data in a Relational
Database.
SQL is a standard, not a software product
Commercial institutions now lead the standard by
extending SQL to meet the needs of business.
The main commercial database management systems
(DBMS) in the industry today are: Oracle (MySQL),
Sybase, Microsoft SQL Server
Database Concepts
Relational Database
What is a Relational Database Management System
(RDBMS)?
All data is stored in Tables (i.e. Relations)
(grid-like format, similar to a spreadsheet)
The logical representation of data is separate from its
physical storage
One high-level language is provided …
for structuring, querying, and changing information.
This, of course, is SQL
Supports the concept of NULL values
Provides Mechanisms for Integrity, Recovery,
Authorization, and Transactions
Database Concepts
Introducing Databases and SQL
Database is also a collection of related facts and figures
regarding one subject matter.
Table is part of database that contains data about one
aspect of a subject in the database.
Record is an instance or a row of a table
Field is an attribute of the record or column of a table.
Database Concepts
Tables
They have Rows and Columns
(like a spreadsheets with rows & columns)
Database Concepts
Database
A Set of Related Tables is called a Database
Tables are separate, but equal in that...
They have no Hierarchical Ranking
They have inherent relationship to each other
You can create relationships
Database Concepts
Entity
An entity is a person, place, or thing for which you
wish to hold information
A table is a collection of separate occurrences of an
Entity
E.g. the “Employee” table contains information about
individual employees
Separate Characteristics are stored for each
Occurrence of an Entity (i.e a row)
E.g. An individual employee has a name, address,
phone number, etc.
Database Concepts
Sample Table
[] Matches any of the characters t[io]e finds tie and toe but not
within the brackets true
! Matches any character not in t[!io] finds true but not to and
the list inside the brackets tie
- Matches one character in a d[a-d]d finds dad, dbd, dcd and
range of characters ddd
24
Database Concepts
SQL Statements – Logical Operators
Operator Description
26
Database Concepts
SQL Statements
RESERVED WORDS DESCRIPTION
Reserved Words - A word in a programming language that has a fixed meaning and
cannot be redefined by the programmer.
Database Concepts
SQL Statements – Sample Database