Skip to content

Instantly share code, notes, and snippets.

@musicalbigfoot
Created June 11, 2013 04:51
Show Gist options
  • Save musicalbigfoot/5754533 to your computer and use it in GitHub Desktop.
Save musicalbigfoot/5754533 to your computer and use it in GitHub Desktop.
PHP: CSV Migration
<?php
$csv = new CSVFile('export.csv');
$return = Array();
$i = 0;
foreach ($csv as $line)
{
$return[$i] = $line;
$i++;
}
if (2==3)
{
echo "<pre>";
print_r($return);
echo "</pre>";
}
$db_host = "XXX";
$db_user = "XXX";
$db_pass = "XXX";
$db_base = "XXX";
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_base);
foreach ($return as $line) {
if (2==3) {
if ( $result = mysql_query($SQLCommand) ) {
echo "Successful!<br><br>";
} else {
echo "Fail: ".mysql_error()."<br><br>";
}
}
}
mysql_close();
class CSVFile extends SplFileObject
{
private $keys;
public function __construct($file)
{
parent::__construct($file);
$this->setFlags(SplFileObject::READ_CSV);
}
public function rewind()
{
parent::rewind();
$this->keys = parent::current();
parent::next();
}
public function current()
{
return array_combine($this->keys, parent::current());
}
public function getKeys()
{
return $this->keys;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment