Simple Blog – Data Model

Simple Blog is a multi-part series. Check out The Index

Pretty simple really. Maybe too simple =) Here’s the DDL to create the database objects used throughout the Simple Blog examples.

##################################################
# Create Database
##################################################
CREATE DATABASE if not exists blog;

GRANT all privileges on blog.*
	to 'blog'@'localhost'
	identified by 'secret';

##################################################
# Create Table
##################################################
USE blog;

CREATE TABLE post (
	id int not null auto_increment primary key,
	title varchar(255) not null,
	content text not null,
	created timestamp not null default current_timestamp
);

##################################################
# Sample Post
##################################################
insert into post (title, content) values ('1st Blog Post', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.');

So, we’ve got 5 basic database commands:

  1. Create a database named “blog”.
  2. Grant full privileges to user “blog” using password “secret”.
  3. Connect to the database.
  4. Create a table named “post” with 4 columns (id, title, content, created).
  5. Insert a sample post into the database.

I suggest creating a SQL script named your_script.sql and piping it’s content to mysql. For example:

mysql < your_script.sql.

Next

PHP with No Bells or Whistles (What not to do)
Simple Blog – Example 1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s