<?php
/*
The definition files I've built this off of are ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHAMCS/sas
The data files are ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHAMCS
Hilariously the public version of ed13for.txt has an error in it. This is good, it prompted me to write in error checking into the class.
*/
$link=mysqli_connect("localhost","root","","nhamcs") or die($link->error);
include("sas2sql.php");
$thingy= new sas2sql();
foreach(array("format"=>"ed14"."for.txt","input"=>"ed14"."inp.txt","label"=>"ed14"."lab.txt","data"=>"ED2014") as $k=>$v){
$fh=fopen($v,"r");
$thingy->$k=fread($fh,filesize($v));
fclose($fh);
}
$thingy->data=trim($thingy->data);
$thingy->name="ed2014";
$thingy->comm=true;
$thingy->save="ed2014.sql";
$thingy->convert();
foreach(explode(";",$thingy->query) as $query) {
if(!empty(trim($query))) $link->query($query) or die($link->error);
}
$result=$link->query($thingy->split_query());
foreach(explode(";",$thingy->split_results($result->fetch_all(),12)) as $query) {
if(!empty(trim($query))) $link->query($query) or die($link->error);
}
$result=$link->query("SHOW TABLES WHERE `Tables_in_nhamcs` LIKE 'ed2014%'") or die($link->error);
$tables=$result->fetch_all();
foreach($tables as $table) {
$result=$link->query($thingy->optimise_query($table[0]));
foreach(explode(";",$thingy->optimise_results($result->fetch_all(),$table[0])) as $query) {
if(!empty(trim($query))) $link->query($query) or die($link->error.$table[0]);
}
}
?>
|