Difference between revisions of "SQL with PDO"
Jump to navigation
Jump to search
(Created page with "==PHP, PDO and MySQL at the Movies== This tutorial takes you through building a web site to show details of Movies held in a database. You will need to have access to a machi...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | ==PHP, PDO and MySQL | + | ==PHP, PDO and MySQL Hello world== |
− | This tutorial takes you through building a web | + | This tutorial takes you through building a web page to show details from database tables. |
You will need to have access to a machine with the LAMP stack - Napier students can use inf08104 or socweb8.napier.ac.uk | You will need to have access to a machine with the LAMP stack - Napier students can use inf08104 or socweb8.napier.ac.uk | ||
Line 12: | Line 12: | ||
==Connect to your own database== | ==Connect to your own database== | ||
*Find out your password | *Find out your password | ||
− | *Download a database | + | *Download a database http://sqlzoo.net/world.sql |
*Import your database into MySQL | *Import your database into MySQL | ||
*Change something about the world | *Change something about the world | ||
Line 29: | Line 29: | ||
*Make up an index page with links to the best movies ever | *Make up an index page with links to the best movies ever | ||
{{#ev:youtube|https://youtu.be/l5F1D8YdbFI}} | {{#ev:youtube|https://youtu.be/l5F1D8YdbFI}} | ||
+ | |||
+ | ==Show more details of each movie== | ||
+ | *Examine the tables movie, casting and actor | ||
+ | *Use a JOIN to include the director | ||
+ | *Write a second query to get the cast list | ||
+ | {{#ev:youtube|https://youtu.be/zsNL2ihVSRo}} |
Latest revision as of 11:57, 10 November 2016
Contents
PHP, PDO and MySQL Hello world
This tutorial takes you through building a web page to show details from database tables.
You will need to have access to a machine with the LAMP stack - Napier students can use inf08104 or socweb8.napier.ac.uk
Exploring the world database with scott
- Connect to the database scott on inf08104
- Run and SQL SELECT statement using PDO
- Output each row in a while loop
Connect to your own database
- Find out your password
- Download a database http://sqlzoo.net/world.sql
- Import your database into MySQL
- Change something about the world
- Update your php to look at your own copy of the world database
Look at one movie from the movie database
- Download the movie database from http://sqlzoo.net/moviesm.sql
- Find the id of "Toy Story"
- Write a PHP query to look up that movie and show details
Use a parameter in your movie query
- Change toystory.php so it takes a CGI variable
- Visit the page with the CGI variable set
- Make up an index page with links to the best movies ever
Show more details of each movie
- Examine the tables movie, casting and actor
- Use a JOIN to include the director
- Write a second query to get the cast list