#!/usr/bin/php -q
// -- CLI check --
/*
if (isset($_SERVER['REQUEST_URI']))
{
This is a web instance
}
else {
This is a CLI instance.
}
*/
$sapi_type = php_sapi_name();
//echo $sapi_tla;
if ($sapi_type != 'cgi')
{
die("
Can only run this script from the CLI
\n");
}
// -- local config --
@include('db.php');
@include('equipment_db.php');
// -- create db --
$db = mysql_select_db($database_name, $connection);
if ($db)
{
echo "db {$database_name} already exists:\n" . mysql_error() . "\n";
}
else
{
$query = "CREATE DATABASE {$database_name}";
$result = mysql_query($query, $connection);
if (!$result)
{
die('Could not create db: ' . mysql_error() . "\n");
}
$db = mysql_select_db($database_name, $connection);
if (!$db)
{
die("Could not select database:\n" . mysql_error() . "\n");
}
}
// -- permissions --
if (false)
{
$query = "GRANT ALL ON {$database_name}.* TO {$dbusername} IDENTIFIED BY \"{$dbpasswd}\"";
$result = mysql_query($query);
if (!$result)
{
die("Could not set permissions:\n" . mysql_error() . "\n");
}
}
// -- create tables --
$t = 0;
do
{
$new_table = $tables[$t];
if (!isset($new_table))
{
break;
}
$query = "SELECT * FROM {$new_table[0]}";
$result = mysql_query($query);
if ($result)
{
echo "table {$new_table[0]} already exists:\n" . mysql_error() . "\n";
}
else
{
$query = "CREATE TABLE {$new_table[0]} {$new_table[1]}";
$result = mysql_query($query);
if (!$result)
{
die("Could not create table {$new_table[0]}:\n" . mysql_error() . "\n");
}
echo "table {$new_table[0]} created:\n" . mysql_error() . "\n";
}
$t++;
} while (true);
// -- init tables --
if (true)
{
$query = "INSERT INTO {$dbt_equipment} VALUES (0, 'sticks set 1 - 12 junour right hand 1.25m')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (1, 'sticks set 2 - 12 junour right hand 1.25m')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (2, 'sticks set 3 - 12 junour right hand 1.25m')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (3, 'ball bag 1 - 25 balls')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (4, 'ball bag 2 - 25 balls')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (5, 'ball bag 3 - 25 balls')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (6, 'goals set 1 - 2 full size golas (1.2 x 1.6 meters)')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (7, 'goals set 2 - 2 half size goals (0.6 x 0.8 meters)')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_equipment} VALUES (8, 'goals set 3 - 2 half size goals (0.6 x 0.8 meters)')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
// ----
$query = "INSERT INTO {$dbt_bookings} VALUES (0, 'user0', '2005-5-5', '2005-6-6')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_bookings} VALUES (1, 'user1', '2005-4-4', '2005-7-7')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_bookings} VALUES (2, 'user0', '2005-3-3', '2005-8-8')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_bookings} VALUES (3, 'user1', '2005-2-2', '2005-9-9')";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
// ----
$query = "INSERT INTO {$dbt_booking_list} VALUES (0, 0)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (0, 1)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (1, 0)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (1, 1)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (1, 2)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (2, 3)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (2, 4)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
$query = "INSERT INTO {$dbt_booking_list} VALUES (3, 5)";
$result = mysql_query($query);
if (!$result)
{
die("Could not insert:\n" . mysql_error() . "\n");
}
}
// ----
return(0);
?>