Geek Austin PHP Class - Session 4

739 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
739
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Geek Austin PHP Class - Session 4

  1. 1. Beginning PHP <ul><li>Session #4 </li></ul><ul><li>November 30, 2010 </li></ul>Josh Butts
  2. 2. Agenda <ul><li>More sessions (briefly) </li></ul><ul><li>Database access, SQL </li></ul><ul><li>Creating a real login system for Vanity </li></ul>
  3. 3. So, Databases... <ul><li>This is what you’re really here for </li></ul><ul><li>PHP & Databases == Peanut Butter & Jelly </li></ul><ul><li>Databases will be your go to method for storing any sort of data for your application </li></ul>
  4. 4. SQL <ul><li>SQL = Structured Query Language </li></ul><ul><li>SQL is how we get data into and out of databases </li></ul><ul><li>Not really a programming language </li></ul><ul><li>Sort of standardized </li></ul>
  5. 5. Queries <ul><li>We write queries as plain text (strings in PHP) </li></ul><ul><li>We execute queries against a database </li></ul><ul><li>The database returns a Result Set </li></ul>
  6. 6. Result Sets <ul><li>Rows and columns of data that come out of a database </li></ul><ul><li>We loop over these to use them in PHP </li></ul><ul><li>We map these to associative arrays access our data </li></ul>
  7. 7. Database Tables <ul><li>One database has many tables </li></ul><ul><li>Think Excel workbook with many sheets </li></ul><ul><li>Tables have a schema </li></ul><ul><ul><li>Named columns </li></ul></ul><ul><ul><li>Definition for what kind of data each column can store </li></ul></ul>
  8. 8. Columns <ul><li>Mainly 2 types </li></ul><ul><ul><li>Various types of strings </li></ul></ul><ul><ul><li>Various types of numbers </li></ul></ul><ul><li>Definition is essentially “is it a string or a number, and how big will it be” </li></ul>
  9. 9. Primary Keys <ul><li>The “id” column </li></ul><ul><li>Usually an integer </li></ul><ul><li>Usually will automatically count up for you as you insert new rows </li></ul><ul><li>Must be unique values </li></ul>
  10. 10. Disclaimer <ul><li>For ease of use, we’re using SQLite, which is slightly different than MySQL </li></ul><ul><li>Some SQL for SQLite may not work on MySQL without a few tweaks </li></ul><ul><li>We’ll cover MySQL later </li></ul>
  11. 11. SELECT queries <ul><li>Gets data out of your database </li></ul><ul><li>Specifies: </li></ul><ul><ul><li>What columns you want </li></ul></ul><ul><ul><li>What table to look at </li></ul></ul><ul><ul><li>What conditions to satisfy </li></ul></ul>
  12. 12. INSERT queries <ul><li>Write new data to your database </li></ul><ul><li>Specifies: </li></ul><ul><ul><li>The table to write to </li></ul></ul><ul><ul><li>Columns to be written to </li></ul></ul><ul><ul><li>Data for each column listed </li></ul></ul>
  13. 13. UPDATE queries <ul><li>Changes existing data in your database </li></ul><ul><li>Specifies: </li></ul><ul><ul><li>Table to write to </li></ul></ul><ul><ul><li>columns and values to update </li></ul></ul><ul><ul><li>How to find the rows to update (usually by primary key or “id”) </li></ul></ul>
  14. 14. DELETE queries <ul><li>Delete data from the database </li></ul><ul><li>Specifies: </li></ul><ul><ul><li>Which table to delete from </li></ul></ul><ul><ul><li>Conditions for which rows should be deleted </li></ul></ul>

×