|
CS479/579 - Web Programming II
|
Displaying ./code/SQL/csv.php
#!/usr/bin/php
drop table if exists people;
create table people (
`id` int,
`name` varchar(64),
`role` enum('Student', 'Employee', 'Faculty'),
`start` date,
`updated` timestamp default current_timestamp()
);
insert into people (id, name, role, start)
values
<?php
$fh = fopen("people.csv", "r");
fgetcsv($fh);
$i = 0;
while (list($id, $name, $role, $start) = fgetcsv($fh)) {
if ($i++ > 0) echo ",\n";
echo "($id, '$name', '$role', '$start')";
}
echo ";\n";
fclose($fh);
?>
|