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