27 Oct 09 PHP & MySQL Database Tutorial: Introduction

Introduction
We use databases to store information and the most popular database used with PHP is MySQL. It’s also free, which is very convenient for us! If you’d like to build a site like Facebook, or store your customer’s order history, or keep an inventory of car parts, then you will need to use a database.

What is MySQL?
MySQL is an open-source relational database system. It is very powerful and chances are that you’ve been to many web sites that were using a MySQL database to show information to you. In fact, MySQL stores all the information on this blog.

Databases consist of tables, which consists of columns and rows of information. Here’s an example of a table:

Table Name: car_parts_inventory

Row # Part Name Part ID
1 Radio F5JG7
2 Muffler GG446

So there’s a very small table that stores information about car parts and their associated ID number. Some large databases may contain hundreds of thousands of rows.

I mentioned earlier that MySQL is a relational database, which basically means that two or more tables can share the same attribute. Let’s do a small example. In our database, we’ll store movie information and use a relation to organize which actors are in the movie.

First we have the table that stores our actors:

Table Name: actors

actor_id actor_name
1 Will Smith
2 Kevin Spacey

And here’s the table that stores our movie information:

Table Name: movies

movie_id movie_name movie_star_actor
1 Independence Day 1
2 The Pursuit of Happyness 1
3 Superman Returns 2
4 Hancock 1
5 Pay It Forward 2

In our movie table we have a unique movie_id for each movie, then the movie’s name, and then a number that represents the actor_id (from the first table) who stars in the movie.

In our next tutorial, we’ll look at how to create our new database in MySQL.

Tags: , , ,