Slide 1
PHP & MYSQL
This Lecture
HTML
PHP
Variables
Arrays
IF…ELSE statements
Loops
Connecting to MySQL
Further reading
W3Schools online tutorials at
http://www.w3schools.com/html
http://www.w3schools.com/php
Learn here
http://www.w3schools.com/html
http://www.w3schools.com/php
PHP & MYSQL
example.zip [files on computer]
Examples HTML/PHP scripts are available to
download from blackboard: example.zip
Unzip it to xampp/htdocs/example
e.g. c:\xampp\htdocs\example\html1.html
e.g. /Application/XAMPP/xamppfiles/htdocs/example/html1.html
Switch on both
Apache (webserver)
MySQL
(MacOSX)
(Win7/8)
PHP & MYSQL
example.zip [files seen on webserver]
Switch on your browser
Go to:
http://localhost/example or
https://localhost/example
Click on any file, note the URL
e.g.
We now discuss them one by one
http://localhost/example/html1.html
http://localhost/example/exp6.php
http://localhost/example
https://localhost/example
PHP & MYSQL
HTML
Readable TEXT
PHP & MYSQL
Basic HTML
My First Heading
My first paragraph.
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
See html1.html
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
PHP & MYSQL
Basic HTML Table
100 | 200 | 300 |
400 | 500 | 600 |
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_tables
tr: table row
td: table data
See html2.html
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_tables
PHP & MYSQL
Basic HTML image
Norwegian Mountain Trip
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_pulpitimage
See html3.html
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_pulpitimage
PHP & MYSQL
The Limitations of SQL
SQL is not a general purpose language
It is designed to create, modify and query
databases
Base on set theory (relational algebra)
Not much normal programming constructs
available
Cannot handle platform-specific challenges such
as formatting output
PHP & MYSQL
Extending SQL
Some DBMSs add programming structures
such as variables and loops to SQL.
Very specific to a DBMS
Essentially a new language that includes SQL
Not hugely flexible
Connect to SQL from another language
Access SQL to run the relevant queries
All other work can be done using procedural code
PHP & MYSQL
ODBC
Connections to databases from programs are
often handled using Open DB Connectivity
Provides a standard interface for communication
with a DBMS
Can run queries, updates etc.
Results of queries can be used inside the program
code
PHP & MYSQL
PHP
PHP is a free, server-side scripting language
Often embedded into web pages to produce
dynamic content
Can connect to most modern DBMSs, and those
implementing ODBC.
Contains specialised functions for connecting to
MySQL
PHP & MYSQL
New to Programming?
Don’t worry!
We will not be introducing too much PHP in this
course
We will teach just enough to connect to MySQL
and produce web pages.
There will be plenty of examples to use
PHP & MYSQL
PHP Basics
PHP is procedural code that can be embedded
into html documents inside php tags. Like this:
example/exp1.php
See exp1.php
PHP & MYSQL
PHP Basics
You can have any number of php blocks,
separated by html. All php blocks will be
connected when the file is run
Code you write in an earlier block can be seen
by code you write in later blocks. This will be
important later
Anything outside a php block is HTML text
PHP & MYSQL
Outputting Text
Inside a PHP block, you can output text using
the echo command. Like SQL, commands end
with a semicolon:
example/exp2.php
See exp2.php
PHP & MYSQL
Outputting HTML
Remember, you’re working in an HTML
document, so anything you output will be
read by the browser as HTML:
“;
echo “
echo ““;
?>