Create your database
Your database is crucial to the performance of your Web site. It should be normalized (the process of assigning attributes to an entity, such as a customer or a product, which helps to avoid data redundancy), and designed with future growth in mind. Database design is beyond the scope of this article so I recommend that someone on your team be familiar with proper design.
I have included the table creation output from mysqldump in the
file example_db.sql (included with the code zip file), so you can set up the database as in the example
code. I have also included some sample data in the file example_db_data.sql,
which you can use to seed the database. Create a database and a MySQL user
to access the database. This user should be given select, insert, update,
and delete privileges on this database. Be sure that you assign these
privileges in the
db table, rather than the
table, for security reasons. The
db table can assign these privileges
to a single database but the
user table assigns privileges to
Import the tables and data using the command:
mysql -u username -p db_name < file.sql
where username is the name of any MySQL user who has access to this database, db_name is the name of your database, and file.sql is the file you are importing.
To run the example PHP code, you need to edit the
script and fill in these values. This script includes two function calls
that connect to the MySQL server and select the database, respectively.
By including these variables and function calls in a separate file, we
can now access the database in any PHP script simply by including the