IS 337: Website Administration

Lecture for November 19: SQL

+
-

Topics

Error Handling in PHP

  • open_db() or die('could not open database');

Reminder: MVC

  • Model, View, Controller
  • Separate them out as much as you can!

SQL and PHP

  • Your choice of backends.
  • SQLite (procedural): toggle
    • sqlite_open($filename, $mode, &$error_message) returns database handle, FALSE if error
    • sqlite_query($db, $query) returns result handle
    • sqlite_fetch_array($result) returns next row as an array, FALSE if no more rows
    • sqlite_exec($db, $query)
  • SQLite (OO): toggle
    • new SQLiteDatabase($filename)
    • $db->query($query)
    • $result->fetch()
  • Security toggle
    • issues:
    • Can users write interesting data into the database?
    • Can user access database file through Apache?
    • SQL injection
  • ORM

Readings and Resources

Quick Written Assignment for Next Time

Write the PHP code to create a new table through a database handle $db.

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.