- By: Nate Baldwin
- For: PHP and MySQL Database
Step 1 - Create the Database Table
Before starting, you'll need to have a MySQL database ready on your server. Instructions for setting that up will depend on who your web host is, and they can usually provide you with some direction for that.
When your database is ready, the first step will be to create a new table in the database to hold all the stats information. We will be creating a table with 5 fields that will need to be in a certain format. Most servers will have a MySQL admin tool such as the most popular, phpMyAdmin. If you have this available, log in to that utility and select your database name.
When your database has been selected (usually a link in the left frame), there should be an option near the bottom of the right frame that looks something like...

Enter the same information you see above - 5 fields in a table named exactly "trackhits". Then hit the Go button and you should end up at another screen to set all the options for the fields. Set your options to look like this...
There will likely be more options that what's shown above, but those can all just be left at whatever the default setting is. The settings shown above are the ones that matter. When finished, hit the Save button to create the table. Now you should have a table that's ready to receive the stats information.
If you do not have phpMyAdmin on your server, or would just prefer to either telnet or command line to the database with text commands, establish a connection to the database (or in phpMyAdmin just hit the SQL tab usually in the top of the right frame). Then use this text command to do the same thing we just did above...
CREATE TABLE trackhits (
id int(11) NOT NULL auto_increment,
page varchar(64) NOT NULL default '',
ip_address varchar(32) NOT NULL default '',
search_string varchar(120) NOT NULL default '',
search_engine varchar(32) NOT NULL default '',
referrer varchar(120) NOT NULL default '',
browser varchar(120) NOT NULL default '',
time_stamp timestamp(14) NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
Either way, we should now be able to continue to the next step.