PHP/MySQL Database-Driven Websites by s5kG1aU


Database-Driven Websites
How it Works

   PHP and MySQL – open source; work on
    both unix and PC platforms
   Dreamweaver has built in tools for
    working with PHP
   PHP has built in tools for working with
   It is easier to do than it first appears
Database Design

   Make a plan
   Entity-Relationship Diagrams
   Use Descriptive Names for Tables
   Select appropriate data types
Build Database (MySQL-Front)
The Linklist Table
The Linklist Table: Dataset
Understanding Queries

 Basic SELECT statement:
SELECT * FROM dbname
 Basic INSERT statement:
INSERT INTO dbname (fieldname1,
  fieldname2) VALUES (value1, value2)
Writing PHP pages

   Connect to the Database
   Perform Queries
   Get data out from database and turn it
    into variables
   Write the variables into formatted output
Connecting to the Database
# Type="MYSQL"
# HTTP="true"
$hostname_linklist = "";
$database_linklist = "comp";
$username_linklist = "comp";
$password_linklist = "password";
$ linklist = mysql_pconnect($hostname_ linklist,
    $username_ linklist, $password_linklist) or
$db = mysql_select_db($database_linklist,$ linklist)
    or die ("Couldn't select database.");
The Link List Example
   A simple HTML annotated list
   A database-driven version of the same list
   Adding records to the database
 Link List Example: Code
I’ve created plain text files of index.php and
   other files in order to show you the code.

   index.php
   input.php
   processForm.php
Link List Example: Includes
Use include files for html that will be used
  on many pages, and for PHP functions
  that will be re-used on many pages in the
  site (such as connecting to the database)

Simplify Site Design
   Use CSS for layouts
   Use include files for common html
   Use include files for database connection
    info (security issue)

To top