Skip to content

Instantly share code, notes, and snippets.

@bhenry
Forked from arschmitz/new_table.php
Created November 16, 2010 18:28
Show Gist options
  • Save bhenry/702221 to your computer and use it in GitHub Desktop.
Save bhenry/702221 to your computer and use it in GitHub Desktop.
<?php
session_start();
$db = mysql_connect("localhost", "bdag", "bdag") or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db("bdaginventory",$db))
die("No database selected.");
$handle = fopen("vehicles.csv", "r");
// Read first (headers) record only)
$data = fgetcsv($handle, 1000, ",");
$sql= 'CREATE TABLE inventorytest (';
$comma = "";
for($i=0;$i<count($data)-1; $i++) {
$sql .= $comma . $data[$i].' VARCHAR(0)';
$comma = ", ";
}
//The line below gets rid of the comma
//$sql = substr($sql,0,strlen($sql)-2);
$sql .= ');';
mysql_query($sql);
echo $sql;
echo "done";
fclose($handle);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment