Import csv file data in database through PHPExcel.

<?php
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHPExcel Reader Example #01</title>
</head>
<body>
<h1>PHPExcel Reader Example #01</h1>
<h2>Simple File Reader using PHPExcel_IOFactory::load()</h2>
<?php
$connection=mysql_connect("127.0.0.1","root","");
mysql_select_db("idegraphics",$connection);
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

$inputFileName = './sampleData/vmpc.csv';
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
 $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
//  Loop through each row of the worksheet in turn
for ($row = 2; $row <= $highestRow; $row++){
    //  Read a row of data into an array
  $make=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0, $row)->getValue();
  $makeid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1, $row)->getValue();
  $modelid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(2, $row)->getValue();
  $model=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(3, $row)->getValue();
  $variantid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(4, $row)->getValue();
  $variant=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(5, $row)->getValue();
  $cc=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(6, $row)->getValue();
  $seatingcapacity=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(7, $row)->getValue();
  $fueltype=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(8, $row)->getValue();
  $fuelid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(9, $row)->getValue();
  $vehiclesegment=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(10, $row)->getValue();
  $segmentid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(11, $row)->getValue();
  $location=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(12, $row)->getValue();
  $price=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(13, $row)->getValue();
  $mainvehicletypeid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(14, $row)->getValue();
  $noofwheels=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(15, $row)->getValue();
  $loactionid=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(16, $row)->getValue();
  $dropdown=$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(17, $row)->getValue();
 
                 
$query = "insert into motors(MAKE,MAKE_ID,MODEL_ID,MODEL,VARIANT_ID,VARIANT,CC,SEATINGCAPACITY,FUELTYPE,FUEL_ID,VEHICLESEGMENT,SEGMENT_ID,LOCATION,
PRICE,MAIN_VEHICLE_TYPE_ID,NOOFWHEELS,LOCATION_ID,DROPDOWN) values('".$make."','".$makeid."','".$modelid."','".$model."','".$variantid."',
'".$variant."','".$cc."','".$seatingcapacity."','".$fueltype."','".$fuelid."','".$vehiclesegment."','".$segmentid."','".$location."','".$price."'
,'".$mainvehicletypeid."','".$noofwheels."','".$loactionid."','".$dropdown."')";
mysql_query($query);
echo mysql_error(); echo '<td>' . $dropdown .'</td><br>';

}
echo '<hr />';
//$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
//var_dump($sheetData);

?>
<body>
</html>

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.