110 likes | 201 Views
Web Development. SQL. What is it?. SQL stands for Structured Query Language It is a text based scripting language for setting up and manipulating databases There are different flavours of SQL depending upon the manufacturer and software used
E N D
Web Development SQL
What is it? • SQL stands for Structured Query Language • It is a text based scripting language for setting up and manipulating databases • There are different flavours of SQL depending upon the manufacturer and software used • E.g. Microsoft SQL has a few differences to other versions • We will be using an open source database: MySQL (pronounced My Sequel)
How it fits in with PHP • Remember that EasyPHP comes as three programs, together known as AMP: • Apache • MySQL • PHP • That’s why MySQL can be used on its own; it is a program in its own right • PHP goes together nicely with MySQL because web apps often need a back end database
Ways to use it • SQL can be used on its own in phpMyAdminor embedded within php code • In phpMyAdmin, the commands can be typed in one at a time or processed in a batch file • To open phpMyAdmin, right click on the php server icon, then select Configuration and phpMyAdmin • SQL commands are written in uppercase. E.g. CREATE (this makes it stand out in the php code)
SQL Commands • CREATE: • Used to create whole databases or tables: • E.g. CREATE DATABASE mydatabase; • CREAT TABLE people; • Note: SQL lines end with a semi colon ;
SQL Commands • INSERT INTO: • Used to add data into tables: • E.g. INSERT INTO people VALUES (1, “fred”);
SQL Commands • SELECT: • Used to query the database • This is the one you really need to know for the assignment! • E.g. SELECT name FROM people; • SELECT * FROM people;
SQL Commands • WHERE: • Used to add criteria to a query • Another one you really need to know for the assignment! • E.g. SELECT name FROM people WHERE age=21;
SQL Commands • LIKE: • Used to add wildcards to a query • E.g. SELECT name FROM people WHERE age LIKE ‘2%’; • This query would return a match for all people with an age that started with 2
SQL Commands • ORDER BY: • Used to sort query results into order • E.g. SELECT name FROM people WHERE age=21 ORDER BY name;
SQL Commands • AND / OR: • Used to make logical choices when querying • E.g. SELECT name FROM people WHERE age>17 AND age<66 ORDER BY name;