create_counter_table.php

<?php

/****************************************

* create_counter_table.php
* flashscript.biz

****************************************/


$link = mysql_connect("localhost", "root", "root");


// if there is no connection we break up.

if (!$link)
{
    fail ("ERROR: Could not connect to database\n");
}


// if the db was not selected we break up.

if (!mysql_select_db("test"))
{
    fail ("ERROR: Could not select test database\n");
}

$tableName = "sitecounter";

// We create the table.

$query = "CREATE TABLE IF NOT EXISTS `$tableName` (
`id` INT(20) NOT NULL AUTO_INCREMENT,
`unique` INT( 20 ) NOT NULL default 0,
`allcounts` INT( 20 ) NOT NULL default 0,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1";

$result = mysql_query($query);

if (!$result)
{
	fail("could not create table");
}

// We add one row, which is necessary for the counter to work.

$query = "INSERT INTO `$tableName` (`id` ,`unique` ,`allcounts`) VALUES ('0', '0', '0');";
$result = mysql_query($query);

if (!$result)
{
	fail("could not add values");
}
else
{
	echo "values added";
}

function fail($msg)
{
	echo $msg;
}
?>