Chapter 2. Creating and configuring the database

As said before, our blog application will need a database. First let's create the database with the following SQL code:

			
CREATE TABLE posts (
	id 				INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	publish_date 	DATETIME NOT NULL,
	title 			VARCHAR(200) NOT NULL,
	content 		TEXT NOT NULL
);

CREATE TABLE comments (
	id 				INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	post_id 		INTEGER NOT NULL,
	publish_date 	DATETIME NOT NULL,
	content 		TEXT NOT NULL
);
		

Will now need to configure the Db plugin so it can access the database. We'll use the Atomik::set() method. It allows you to define keys in the global store. In the app/config.php file, add the following lines:

			
Atomik::set('plugins/Db', array(
	'dsn' 		=> 'mysql:host=localhost;dbname=blog',
	'username' 	=> 'root',
	'password' 	=> ''
));
		

You can see that we define the plugins/Db key as an array containing connection information. Modify the host, dbname, username and password parameters according to your setup.

This is all we need to connect to the database.