PHP 13
PHP 13
PHP-13
Sorting data with PHP
Variable
Form variable
Session variable
Available to all pages during the session as long as the browser window is
$_SESSION['cust_name'] open. But forgotten after the session
Cookie
Available to all pages and client-side code, even after browser window is
$_COOKIE['cust_name'] closed. Expiry date set in the code
Data available to all pages and remains stored until deleted. Can be stored
Database data
infinitely.
Server Side Programming
HTTP Request PHP
HTML
HTTP Response
HTML
HTTP Response
MySQL
Database
HTTP Request PHP
HTML
HTTP Response
• Databases abstract the data storage process and take care of the details
Primary Key
3 Mike McGrath (086)-123-4567 mike@mcgrath.com
3 Mike a record
McGrath (086)-123-4567 mike@mcgrath.com
1 Titanic
1 John Smith (087)123-4567 js@gmail.com
2 Men in Black
4 Central do Brazil
3 Mike McGrath (086)-123-4567 mike@mcgrath.com
5 Young Offenders
• Connections can be made between tables by including the key from one
table to a row
2 Men in Black
member_id fname lname tel email
3 Star Wars
5 Young Offenders
2 Ann Jones (087)555-1234 ann.j@google.com
2 Men in Black
member_id fname lname tel email
3 Star Wars
5 Young Offenders
Foreign Key
2 Ann Jones (087)555-1234 ann.j@google.com
DECIMAL
DECIMAL(5,2) permits valuse from -999.99 to 999.99
YEAR A year between 1901-2155 (notice there are 256 possible values 1 byte)
CHAR()
CHAR(50) will be 50 characters long, padded if necessary.
VARCHAR()
VARCHAR(50) can hold strings of up to 50 characters or less (no padding)
• Consequently any SQL skills you develop will be valuable for a long time
HTML Data
Tables
S.Q.L.
It is also possible to issue commands directly to the DBMS using the
command line and SQL
http://localhost/phpmyadmin
RETRO-VISION
PARTY LIKE IT'S 1999
customers
id fname sname tel email pword
1 John Smith 0871234567 js@gmail.com pw1234
2 Ann Jones 0875551234 ann.j@google.com password
3 Mike McGrath 0861234567 mike@mcgrath.com secret
4 Fionn Murphy 0836669999 murph96@hotmail.com hotty96
CREATE TABLE IF NOT EXISTS customers
(
id INT AUTO_INCREMENT PRIMARY KEY,
fname VARCHAR(25) NOT NULL,
sname VARCHAR(30) NOT NULL,
tel VARCHAR(10),
email VARCHAR(50) UNIQUE NOT NULL,
pword VARCHAR(30) NOT NULL
)
INSERT INTO customers (fname, sname, tel, email, pword)
18 went in by default
Updating fields
UPDATE dvds
• This will update the theyear field in every row that has "Central do
Brazil" in the title field
?
)
Rentals Table
• The right way to do the table depends on whether or not we can to keep
track of historic rentals or just the current rentals
Rental History
Current rentals
3 1 5 15/03/2018
4 4 12 22/05/2018
JOIN
id name id colour
1 Tom
1 red
2 Dick
2 black
5 Harry
3 blue
6 Mary
JOIN
1 Tom 2 black