Databases

warning: Creating default object from empty value in /home/coredogs/public_html/modules/taxonomy/taxonomy.pages.inc on line 33.

Programs on servers

See more about:

Learn:

  • How to manually create a Web page with a product list.
  • How easy it is to make a mistake.
  • A Web server can automatically create a product list page from data in a database. This reduces the number of mistakes.

Sample: DogRock

See more about:

The DogRock site lets:

  • Users see a list of articles, and read each one.
  • Writers add and change articles, quickly and easily.
  • Webers update the Web site, quickly and easily.

Sample: DogToys

See more about:

Let’s tour the DogToys Web site. The site helps:

  • Customer look at product data.
  • Employees easily change product data.
  • Webers easily alter the Web site.

Tools for developers

See more about:

You’ll learn:

  • To do database work, you need to send SQL statements to a DBMS. But some SQL statements are long and easy to mess up.
  • phpMyAdmin is a PHP Web application that writes SQL for you. phpMyAdmin is part of XAMPP.
  • You’ll see how to start MySQL and phpMyAdmin on your computer. You’ll see how to use phpMyAdmin on your hosting account.
  • You can create databases on your local computer, and use phpMyAdmin to export your work to your hosting account.

Drilling down

Learn that:

  • Drilling down means going from summary to detail.
  • On a summary page, use PHP to create links that include a primary key value.
  • On a detail page, get the primary key value from the link, and use it to fetch detail data from the database.

Handling errors

Using databases adds more things that can go wrong. In this lesson, we’ll see how you can handle database errors.

We’ll talk about two new types of errors:

  • Database connection errors
  • SQL errors

You can check for both.

We’ll also talk about simple server-side validation. Even if you can check all data on the client, you should check it on the server as well. To foil Evil Doers.

Editing records

See more about:

Learn:

  • The add and edit forms are similar, the edit form has data already in it, and passes around an id number.
  • The SQL UPDATE statement changes data in an existing record. Usually, it has a single primary key value in its WHERE clause.

Deleting records

See more about:

Learn:

  • On the admin menu, there’s a delete link for each record. It includes the id of the record.
  • Clicking the delete link shows a confirmation page. This page shows all of the data in the record to be deleted. It has a form with a hidden field containing the record id, and a confirmation button.
  • If the user confirms the delete, another PHP program creates and runs an SQL DELETE statement.

The administration menu

See more about:

Learn that:

  • Our applications’ sites have two parts: one for regular users, and one for administration.
  • The admin menu lists items (products or articles), with Edit and Delete links for each.

Showing sorted data

See more about:

Learn:

  • The ORDER BY clause of the SELECT statement tells MySQL to sort records in the record set.
  • Let users choose the sort order by adding a GET parameter to links. Add code that will append different fields to ORDER BY, depending on the parameter.
  • The LIMIT clause of the SELECT statement sets the maximum number of records MySQL will add to a record set.

Lessons

How to...


Dogs