Please Help!
The DATE field is not populated when I am importing data from csv file.
Instead of the actual data I get 0000-00-00 for all records in this field.
here is my table:
symbol varchar(10)
date date
open decimal(4,2)
high decimal(4,2)
low decimal(4,2)
close decimal(4,2)
volume int(10)
adjclose decimal(4,2)
here is sample data from the file:
Date Open High Low Close Volume Adj Close*
10-Dec-04 24.25 24.79 23.64 23.75 22,800 23.75
9-Dec-04 24.53 25.00 24.11 24.25 9,100 24.25
here is the code I am using to import the data:
while ($row) {
$symbol = $row['symbol'];
$file = "./test.csv";
$fcontents = file ("$file");
for($i=1; $i<(sizeof($fcontents)-1); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
# data is tab '\t' or ',' comma separated
$sql = "insert into data (symbol,date,open,high,low,close,volume,adjclose) values ('". $symbol ."','". implode("','", $arr) ."')";
mysql_query($sql);
}
echo $row['symbol'] ."- data imported<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
$row = mysql_fetch_array($getsymbol);
}