Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Girl Develop It! PHP/MySQL Session 2

kperch
November 06, 2011

Girl Develop It! PHP/MySQL Session 2

Session 2- Intro MySQL

kperch

November 06, 2011
Tweet

More Decks by kperch

Other Decks in Technology

Transcript

  1. What is MySQL? An engine for SQL SQL: Structured Query

    Language Relational Database System
  2. What does the relational mean? You can have tables related

    to each other through the use of keys and indexes key- a column of a table that contains a unique value for each row primary: for this table (can NOT repeat) foreign: relates to another record in another table (can repeat) index- a column that where the values in the rows are kept in order and in an index for faster searching
  3. Getting started Using LAMP/WAMP/MAMP, find out how to get to

    your PHPMyAdmin page Take a peek around
  4. Structured Query Language (SQL) How you give the data base

    commands Keywords are generally capitalized, but depending on the engine/frontend you use, you don’t have to. Generally better safe than sorry. Several types of queries: CREATE, INSERT, SELECT, ALTER, DROP Once you get the basic patterns down, you can add in conditions/options
  5. CREATE statements Create a database or a table Syntax: CREATE

    DATABASE {itemName}; For Tables: CREATE TABLE tableName( fieldName fieldType [options], field2Name fieldType [options], ); See example2-1.sql for database/table creation
  6. INSERT Statements These insert records into tables Syntax: INSERT INTO

    tableName VALUES(col1Value, col2Value, col3Value...); Can also add to only certain columns for a row, ignoring the rest See example 2-2.sql for examples
  7. SELECT Statements Select row(s) from a table Syntax: SELECT *

    from TableName WHERE col1=val1 AND col2 = val2 [OPTIONS] See example2-3.sql
  8. WHERE clause Where a column equals a value Can use

    AND, OR logic, = or != Can use IS NULL or IS NOT NULL See example 2-4.sql
  9. Selecting only certain columns Replace the * after SELECT with

    the names of the columns you would like to select Example: SELECT username, password from User... See example2-5.sql for examples
  10. LIMIT option SELECT ...WHERE... LIMIT x, y; Selects y records,

    starting with x See example 2-6.sql for examples
  11. ORDER BY option SELECT...WHERE...ORDER BY fieldName ASC/DESC Orders the results

    by the fieldName column either ASCending or DESCending See Example2-7.sql for examples
  12. Joins Joins are select statements that select rows from more

    than one table, based on a foreign key relationship between the rows of data selected. Three types: left, right, inner To see exactly how these works, see example2-8.sql
  13. Homework Design two tables that match something in real life

    and would logically form a join. Write a few queries that would make sense for these tables, including a join select.