<?php
// Cfg / function for inet zasuvky CSV
// (UTF 8) Php/mysql
@ini_set('error_reporting', E_ALL);
@ini_set("display_errors", "on"); 
error_reporting(E_ALL);

session_start();

include 'class_pdo_mini.php';

$CFG_SQL = array(
	'debug' => true,
	'host'  => 'localhost',
	'user'  => 'root',
	'psw'   => '',
	'db'    => 'test',
	'prefix'=> 'zas2_'
	);
$SQL = new classSql($CFG_SQL);

$filename = 'zasuvky_bn13.csv';
$x = 'rack;zařízení;zásuvka;vede do zařízení;...a zásuvky;kabel;pozn.;místnost;infrastruktura;co;VLAN;Port security;MAC;IP;OS;skupina;name;ústav;patro;pozn. 2';
$y = explode(';',$x);
$cols = array();
foreach($y as $key=>$value)
	{$cols[] = 'data'.$key;}	// create col names
$cols = implode(',',$cols);
//echo $cols;

//c:\wamp\bin\mysql\mysql5.6.17\data\test\
$path='';
//$path = 'http://localhost/zelus-new/zasuvky-csv/';
//$path = 'c:\wamp\www\zelus-new\zasuvky-csv\\';
//$path = 'file:///c:/wamp/www/zelus-new/zasuvky-csv/';
$path = '/wamp/www/zelus-new/zasuvky-csv/';	//wamp server, www folder = c:\wamp\www\
$path = '/xampp/htdocs/www/zelus-new/zasuvky-csv/';	//wamp server, www folder = c:\wamp\www\
//C:\xampp\htdocs\www\zelus-new\zasuvky-csv

$file = $path.$filename;
$query = <<<eof
    LOAD DATA INFILE '$file'
      INTO TABLE `zas2_data`
      CHARACTER SET 'cp1250'
      FIELDS TERMINATED BY ';'
      OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '\r\n'
      IGNORE 1 LINES
    ($cols)
eof;

// 	utf8_czech_ci | utf8_unicode
$SQL->query('SET NAMES \'utf8\'');
//$SQL->query('SET NAMES \'cp1250\'');
//$SQL->query('SET NAMES \'latin1\'');

$SQL->query('TRUNCATE TABLE `zas2_data`');
$SQL->query($query);
?>