include("./datesconfig.php");
// This needs to be altered if you have a different name or location for the data file
$datasource = "./today.dat";
$conn = @mysql_connect($server,$user,$pass) or die ("unable to connect");
$select = mysql_select_db($database,$conn) or die ("unable to select db");
mysql_query( "DROP TABLE IF EXISTS `$table`" ) or die("Drop Error: ".mysql_error());
//create table (default MyISAM table)
mysql_query( "CREATE TABLE $table(
id INT NOT NULL AUTO_INCREMENT,
eventtype Char(1),
eventmonth smallint(2),
eventday smallint(2),
eventyear smallint(4),
weekday smallint(1),
article text,
PRIMARY KEY(id),
KEY(eventday,eventmonth)
)")
or die("Create table Error: ".mysql_error());
// add new/updated data from file
$lines = file($datasource);
foreach ($lines as $line_num => $line) {
// split each line;
echo "$line
\n";
$et = substr($line, 0, 1);
$em = substr($line, 1, 2);
$ed = substr($line, 3, 2);
$ey = substr($line, 5, 4);
$wd = substr($line, 9, 1);
$a = substr($line, 10, strlen($line) - 9);
$a = addslashes($a);
echo "$et, $em, $ed, $ey, $wd, $a
\n"; mysql_query ("INSERT INTO $table (eventtype, eventmonth, eventday, eventyear, weekday, article) VALUES ('$et','$em','$ed','$ey','$wd','$a')") or die("Insert Error: ".mysql_error()); } mysql_close($conn); echo " Success "; ?>