12. Some Database Work
Setting up some of the Database
Now that we have a working registration, and login system - we're going to need an area to hold all of our Status updates, Wall posts, etc.
To start off, we're going to create our Status table. This is the SQL you'll need to create the table; or you can do it visually. I'll give you both.
Status Table
SQL
CREATE TABLE IF NOT EXISTS `Status` (
`ID` bigint(19) NOT NULL AUTO_INCREMENT,
`UID` int(10) DEFAULT NULL,
`Type` varchar(20) NOT NULL DEFAULT 'Post',
`Content` text,
`Date` bigint(11) NOT NULL,
KEY `ID` (`ID`),
KEY `UID` (`UID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Comment Table
Now let's create our Comment Table. We'll call it "Status_Comment", simply to group the table together with "Status".
SQL
CREATE TABLE IF NOT EXISTS `Status_Comment` (
`Status_ID` bigint(20) NOT NULL,
`ID` int(10) NOT NULL AUTO_INCREMENT,
`UID` int(10) NOT NULL,
`Content` text NOT NULL,
`Date` bigint(12) NOT NULL,
PRIMARY KEY (`ID`),
KEY `Status_ID` (`Status_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Liking Your Status Table
We need 2 tables for Likes. One for our status, and one for comments of our status. This one is for our status, called "Status_Like".
SQL
CREATE TABLE IF NOT EXISTS `Status_Like` (
`Status_ID` int(10) NOT NULL,
`UID` int(10) NOT NULL,
`iLike` tinyint(1) NOT NULL DEFAULT '1',
KEY `Status_ID` (`Status_ID`),
KEY `UID` (`UID`),
KEY `iLike` (`iLike`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Liking a comment
This table we will name "Status_Comment_Like".
SQL
CREATE TABLE IF NOT EXISTS `Status_Comment_Like` (
`Status_ID` int(10) NOT NULL,
`Status_Comment_ID` int(10) NOT NULL,
`UID` int(10) NOT NULL,
`iLike` tinyint(1) NOT NULL DEFAULT '1',
KEY `Status_Comment_ID` (`Status_Comment_ID`),
KEY `Status_ID` (`Status_ID`),
KEY `iLike` (`iLike`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
This is just to prep us for what code we'll write to insert into here. We can't actually do anything with it just yet. Next we will put together the basic body, and add a few more tables.
For anyone who wants to skip over the step by step, you can insert this file (after you download it) into your phpMyAdmin (or other system). Typically, just click import, then select the downloaded file. It will create your 4 tables for you.