2011-09-05 3 views
0

고객을위한 맞춤형 가격 책정 매트릭스를 개발 중이며 옵션이 다른 제품을 구별하는 코드가 있습니다. 6 가지 다른 유형의 재료가 있기 때문에 하나의 코드에 6 가지 변형이 있습니다. 다른 비용, 다른 볼트 온은 재료에 따라 코드 및 비용을 변경합니다 ... 등등.CSV에서 PHP 로의 JSON을 MySQL에

는 나는 당신에게 내 가격 데이터베이스 구조 (MySQL의)

|------ 
|Field|Type|Null|Default 
|------ 
|//**id**//|mediumint(9)|No| 
|jp_code|varchar(7)|No| 
|brand_rate|text|No| 
|price_25|text|No| 
|price_50|text|No| 
|price_100|text|No| 
|price_250|text|No| 
|price_500|text|No| 
|price_1000|text|No| 

나는 가격과 브랜드 속도 필드에서 JSON 각 코드에 대한 모든 6 개 가격 저장을 보여줌으로써 시작합니다

이 나중에 JS에 의해 처리된다 .

그래서 해당 데이터베이스에 대한 일반적인 항목은 다음과 같습니다

|1|JP6000|["F","F","n\/a","F","F","F"]|["2.92","2.92","n\/a","4.86","6.35","7.62"]|["2.77","2.77","n\/a","4.62","6.03","7.24"]|["2.55","2.55","4.21","4.25","5.55","6.66"]|["2.45","2.45","3.83","4.08","5.33","6.40"]|["2.38","2.38","3.64","3.96","5.17","6.20"]|["2.50","2.33","3.47","3.89","5.08","6.10"] 

클라이언트는 원활이 가격을 업데이트 할 수 CSV를 업로드 할 수 있어야합니다.

CSV 파일은 다음과 같이됩니다 : 당신은 MySQL의 행 항목을 살펴 경우 CSV File

은 그렇게 문제에 데이터를 결혼 할 수 있어야한다! parseCSV의 v0.4.3 베타 나는이 같은 JP 코드에 의해 그룹에 모든 결과를이 가지고 http://code.google.com/p/parsecsv-for-php/

: 그래서

array(2) { 
    ["JP6000"]=> 
    array(6) { 
    [0]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "2.92" 
     ["Price_50"]=> 
     string(4) "2.77" 
     ["Price_100"]=> 
     string(4) "2.55" 
     ["Price_250"]=> 
     string(4) "2.45" 
     ["Price_500"]=> 
     string(4) "2.38" 
     ["Price_1000"]=> 
     string(4) "2.33" 
     ["Material"]=> 
     string(10) "Belluno PU" 
    } 
    [1]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "2.92" 
     ["Price_50"]=> 
     string(4) "2.77" 
     ["Price_100"]=> 
     string(4) "2.55" 
     ["Price_250"]=> 
     string(4) "2.45" 
     ["Price_500"]=> 
     string(4) "2.38" 
     ["Price_1000"]=> 
     string(4) "2.33" 
     ["Material"]=> 
     string(9) "Torino PU" 
    } 
    [2]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(3) "n/a" 
     ["Price_25"]=> 
     string(3) "n/a" 
     ["Price_50"]=> 
     string(3) "n/a" 
     ["Price_100"]=> 
     string(4) "4.21" 
     ["Price_250"]=> 
     string(4) "3.83" 
     ["Price_500"]=> 
     string(4) "3.64" 
     ["Price_1000"]=> 
     string(4) "3.47" 
     ["Material"]=> 
     string(11) "Full Colour" 
    } 
    [3]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "4.86" 
     ["Price_50"]=> 
     string(4) "4.62" 
     ["Price_100"]=> 
     string(4) "4.25" 
     ["Price_250"]=> 
     string(4) "4.08" 
     ["Price_500"]=> 
     string(4) "3.96" 
     ["Price_1000"]=> 
     string(4) "3.89" 
     ["Material"]=> 
     string(8) "Finecell" 
    } 
    [4]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "6.35" 
     ["Price_50"]=> 
     string(4) "6.03" 
     ["Price_100"]=> 
     string(4) "5.55" 
     ["Price_250"]=> 
     string(4) "5.33" 
     ["Price_500"]=> 
     string(4) "5.17" 
     ["Price_1000"]=> 
     string(4) "5.08" 
     ["Material"]=> 
     string(5) "Nappa" 
    } 
    [5]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "7.62" 
     ["Price_50"]=> 
     string(4) "7.24" 
     ["Price_100"]=> 
     string(4) "6.66" 
     ["Price_250"]=> 
     string(3) "6.4" 
     ["Price_500"]=> 
     string(3) "6.2" 
     ["Price_1000"]=> 
     string(3) "6.1" 
     ["Material"]=> 
     string(8) "Richmond" 
    } 
    } 
    ["JP6010"]=> 
    array(6) { 
    [0]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "3.41" 
     ["Price_50"]=> 
     string(4) "3.24" 
     ["Price_100"]=> 
     string(4) "2.98" 
     ["Price_250"]=> 
     string(4) "2.86" 
     ["Price_500"]=> 
     string(4) "2.78" 
     ["Price_1000"]=> 
     string(4) "2.73" 
     ["Material"]=> 
     string(10) "Belluno PU" 
    } 
    [1]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "3.41" 
     ["Price_50"]=> 
     string(4) "3.24" 
     ["Price_100"]=> 
     string(4) "2.98" 
     ["Price_250"]=> 
     string(4) "2.86" 
     ["Price_500"]=> 
     string(4) "2.78" 
     ["Price_1000"]=> 
     string(4) "2.73" 
     ["Material"]=> 
     string(9) "Torino PU" 
    } 
    [2]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(3) "n/a" 
     ["Price_25"]=> 
     string(3) "n/a" 
     ["Price_50"]=> 
     string(3) "n/a" 
     ["Price_100"]=> 
     string(4) "4.77" 
     ["Price_250"]=> 
     string(4) "4.33" 
     ["Price_500"]=> 
     string(4) "4.13" 
     ["Price_1000"]=> 
     string(4) "3.93" 
     ["Material"]=> 
     string(11) "Full Colour" 
    } 
    [3]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "5.41" 
     ["Price_50"]=> 
     string(4) "5.14" 
     ["Price_100"]=> 
     string(4) "4.74" 
     ["Price_250"]=> 
     string(4) "4.55" 
     ["Price_500"]=> 
     string(4) "4.41" 
     ["Price_1000"]=> 
     string(4) "4.33" 
     ["Material"]=> 
     string(8) "Finecell" 
    } 
    [4]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(3) "6.9" 
     ["Price_50"]=> 
     string(4) "6.56" 
     ["Price_100"]=> 
     string(4) "6.04" 
     ["Price_250"]=> 
     string(3) "5.8" 
     ["Price_500"]=> 
     string(4) "5.63" 
     ["Price_1000"]=> 
     string(4) "5.52" 
     ["Material"]=> 
     string(5) "Nappa" 
    } 
    [5]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "8.28" 
     ["Price_50"]=> 
     string(4) "7.87" 
     ["Price_100"]=> 
     string(4) "7.25" 
     ["Price_250"]=> 
     string(4) "6.96" 
     ["Price_500"]=> 
     string(4) "6.76" 
     ["Price_1000"]=> 
     string(4) "6.62" 
     ["Material"]=> 
     string(8) "Richmond" 
    } 
    } 
} 
array(2) { 
    ["JP6000"]=> 
    array(6) { 
    [0]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "2.92" 
     ["Price_50"]=> 
     string(4) "2.77" 
     ["Price_100"]=> 
     string(4) "2.55" 
     ["Price_250"]=> 
     string(4) "2.45" 
     ["Price_500"]=> 
     string(4) "2.38" 
     ["Price_1000"]=> 
     string(4) "2.33" 
     ["Material"]=> 
     string(10) "Belluno PU" 
    } 
    [1]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "2.92" 
     ["Price_50"]=> 
     string(4) "2.77" 
     ["Price_100"]=> 
     string(4) "2.55" 
     ["Price_250"]=> 
     string(4) "2.45" 
     ["Price_500"]=> 
     string(4) "2.38" 
     ["Price_1000"]=> 
     string(4) "2.33" 
     ["Material"]=> 
     string(9) "Torino PU" 
    } 
    [2]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(3) "n/a" 
     ["Price_25"]=> 
     string(3) "n/a" 
     ["Price_50"]=> 
     string(3) "n/a" 
     ["Price_100"]=> 
     string(4) "4.21" 
     ["Price_250"]=> 
     string(4) "3.83" 
     ["Price_500"]=> 
     string(4) "3.64" 
     ["Price_1000"]=> 
     string(4) "3.47" 
     ["Material"]=> 
     string(11) "Full Colour" 
    } 
    [3]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "4.86" 
     ["Price_50"]=> 
     string(4) "4.62" 
     ["Price_100"]=> 
     string(4) "4.25" 
     ["Price_250"]=> 
     string(4) "4.08" 
     ["Price_500"]=> 
     string(4) "3.96" 
     ["Price_1000"]=> 
     string(4) "3.89" 
     ["Material"]=> 
     string(8) "Finecell" 
    } 
    [4]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "6.35" 
     ["Price_50"]=> 
     string(4) "6.03" 
     ["Price_100"]=> 
     string(4) "5.55" 
     ["Price_250"]=> 
     string(4) "5.33" 
     ["Price_500"]=> 
     string(4) "5.17" 
     ["Price_1000"]=> 
     string(4) "5.08" 
     ["Material"]=> 
     string(5) "Nappa" 
    } 
    [5]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6000" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "7.62" 
     ["Price_50"]=> 
     string(4) "7.24" 
     ["Price_100"]=> 
     string(4) "6.66" 
     ["Price_250"]=> 
     string(3) "6.4" 
     ["Price_500"]=> 
     string(3) "6.2" 
     ["Price_1000"]=> 
     string(3) "6.1" 
     ["Material"]=> 
     string(8) "Richmond" 
    } 
    } 
    ["JP6010"]=> 
    array(6) { 
    [0]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "3.41" 
     ["Price_50"]=> 
     string(4) "3.24" 
     ["Price_100"]=> 
     string(4) "2.98" 
     ["Price_250"]=> 
     string(4) "2.86" 
     ["Price_500"]=> 
     string(4) "2.78" 
     ["Price_1000"]=> 
     string(4) "2.73" 
     ["Material"]=> 
     string(10) "Belluno PU" 
    } 
    [1]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "3.41" 
     ["Price_50"]=> 
     string(4) "3.24" 
     ["Price_100"]=> 
     string(4) "2.98" 
     ["Price_250"]=> 
     string(4) "2.86" 
     ["Price_500"]=> 
     string(4) "2.78" 
     ["Price_1000"]=> 
     string(4) "2.73" 
     ["Material"]=> 
     string(9) "Torino PU" 
    } 
    [2]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(3) "n/a" 
     ["Price_25"]=> 
     string(3) "n/a" 
     ["Price_50"]=> 
     string(3) "n/a" 
     ["Price_100"]=> 
     string(4) "4.77" 
     ["Price_250"]=> 
     string(4) "4.33" 
     ["Price_500"]=> 
     string(4) "4.13" 
     ["Price_1000"]=> 
     string(4) "3.93" 
     ["Material"]=> 
     string(11) "Full Colour" 
    } 
    [3]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "5.41" 
     ["Price_50"]=> 
     string(4) "5.14" 
     ["Price_100"]=> 
     string(4) "4.74" 
     ["Price_250"]=> 
     string(4) "4.55" 
     ["Price_500"]=> 
     string(4) "4.41" 
     ["Price_1000"]=> 
     string(4) "4.33" 
     ["Material"]=> 
     string(8) "Finecell" 
    } 
    [4]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(3) "6.9" 
     ["Price_50"]=> 
     string(4) "6.56" 
     ["Price_100"]=> 
     string(4) "6.04" 
     ["Price_250"]=> 
     string(3) "5.8" 
     ["Price_500"]=> 
     string(4) "5.63" 
     ["Price_1000"]=> 
     string(4) "5.52" 
     ["Material"]=> 
     string(5) "Nappa" 
    } 
    [5]=> 
    array(9) { 
     ["Code"]=> 
     string(6) "JP6010" 
     ["Brand Rate"]=> 
     string(1) "F" 
     ["Price_25"]=> 
     string(4) "8.28" 
     ["Price_50"]=> 
     string(4) "7.87" 
     ["Price_100"]=> 
     string(4) "7.25" 
     ["Price_250"]=> 
     string(4) "6.96" 
     ["Price_500"]=> 
     string(4) "6.76" 
     ["Price_1000"]=> 
     string(4) "6.62" 
     ["Material"]=> 
     string(8) "Richmond" 
    } 
    } 
} 

내가 CSV 파일로 작업하려면이 옵션을 사용하고

내가해야 할 일은이 데이터를 추가로 그룹화하고 각 코드에 대한 정보를 사용하여 MySQL 레코드에서 보는 것처럼 JSON 문자열로 변환하는 것입니다.

JP6000위한 price_25 JSON 배열의 첫 번째 항목이 2.92 및 제 2.92 것 - 제 인 N/A는

이것도 통해 루프에 요구하고 JP 코드는 기본 인에 기초하여 이에 따라 각각의 MySQL 행을 업데이트 키.

나는 이것이 모두 의미가 있기를 바랍니다. 매우 까다 롭습니다!

+0

표준 대답은 JSON 형식의 데이터를 저장하지 않습니다. 프레젠테이션을위한 것입니다. – ajreal

+0

도움이되는 의견을 보내 주셔서 감사합니다 ... 불행히도 모든 것이 마법처럼 작동하는 것은 아니므로 클라이언트에게 '아니오'라고 말하지 않는 방법을 찾아야합니다. 이것이이 솔루션을 제공 할 수있는 유일한 방법입니다. –

답변

1
$rows = array(); 
$format = array('brand_rate'=>'Brand Rate','price_25'=>'Price_25','price_50'=>'Price_50','price_100'=>'Price_100','price_250'=>'Price_250','price_500'=>'Price_500','price_1000'=>'Price_1000'); 

// Build $rows array 
foreach ($groupedData as $jpCode => $jpData) { 
    foreach ($jpData as $rowIndex => $rowData) { 
    foreach ($format as $csvCol) { 
     $rows[$jpCode][$csvCol][$rowIndex] = $rowData[$csvCol]; 
    } 
    } 
} 

// Loop through $rows and INSERT them 
foreach ($rows as $jpCode => $row) { 
    $cols = $vals = $duplicates = array(); 
    foreach ($format as $sqlCol => $csvCol) { 
    $val = mysql_real_escape_string(json_encode($row[$csvCol])); 
    $duplicates[] = "`$sqlCol` = '$val'"; 
    $cols[] = $sqlCol; 
    $vals[] = $val; 
    } 
    $query = "INSERT INTO `dbname`.`tablename` (`jp_code`,`".implode('`,`',$cols)."`) VALUES ('$jpCode','".implode("','",$vals)."') ON DUPLICATE KEY UPDATE ".implode(", ",$duplicates); 
    mysql_query($query); 
} 

이 당신이 MySQL을 사용하는 것처럼, 당신은 이전 스타일의 MySQL의 확장 등을 사용하고, 가정을 많이하게되지 PDO, 당신의 분석 데이터는 $groupedData라는 변수, 등 등에 저장되어

거기에 수행 할 수있는 상당한 최적화가있을 것입니다, 나는 그 많은 foreach 루프를 사용하는 것을 싫어하지만 이것은 단지 간단한 예일뿐입니다. jp_code에 고유 색인을 추가하고이 색인에 ON DUPLICATE KEY UPDATE을 추가하는 것이 좋습니다.

나는 그것을 테스트하지 않았기 때문에 100 % 정확하지는 않을 것이지만 나는 적어도 당신에게 올바른 방향으로 자극을 줄 것이라고 확신한다. 이 JSON 객체가 아닌 배열로 데이터베이스로 필드를 넣어 것입니다,하지만 당신은 JS 측에게 예상대로 그들은 (희망) 여전히 같은 방식으로 작동해야

편집

참고. ..

참고 DB 스키마에서 CSV 필드가 누락되어 있으므로 Material CSV 필드에 아무 것도하지 않았습니다.

나는 또한 쿼리 코드에 ON DUPLICATE KEY UPDATE 절을 추가했습니다.

+0

그것은 아름답게 일했습니다, 정말 고마워요! –

0

내 수업을 고려하고 싶을 수도 있습니다. 그것은 당신의 CSV를 MySQL로 변환합니다. QUERY, Array를 JSON과 HTML 테이블에 삽입하십시오.

/** 
* CSV_parser 
* 
* @package 
* @author Dave's Simple Project 
* @copyright MESMERiZE 
* @version 2012 
* @access public 
*/ 
class CSV_parser 
{ 
    private $source; 
    private $array; 
    private $length; 
    private $delimiter; 
    private $class; 
    private $padding; 
    private $border; 
    private $id; 
    private $width; 

    /** 
    * CSV_parser::__construct() 
    * 
    * @param mixed $source 
    * @param integer $length 
    * @param string $delimiter 
    * @return 
    */ 
    public function __construct($source, $length = 8000, $delimiter = ',') 
    { 
     try 
     { 
      // Lets try to open the file and check if its readable else throw an error. 
      if (!isset($source) || !is_readable($source)) 
      { 
       throw new Exception('File Not Found!'); 
       return false; 
      } else 
      { 
       //set the source file 
       $this->source = $source; 
       $this->length = $length; 
       $this->delimiter = $delimiter; 
       return true; 
      } 
     } 
     catch (exception $e) 
     { 
      // Send an error message :) 
      echo $e->getMessage(); 
     } 
     parent::__construct(); 
    } 
    /** 
    * CSV_parser::toArray() 
    * 
    * @return 
    */ 
    public function toArray() 
    { 
     // 1. First open the source file 
     $handler = fopen($this->source, 'r'); 
     // 2. Turn the CSV to array 
     while (($data = fgetcsv($handler, $this->length, $this->delimiter)) !== false) 
     { 
      $a[] = $data; 
     } 
     // 3. Get the first index to be used as the key 
     $h = $a[0]; 
     // 4. Lets remove the $h variable's empty values 
     foreach ($h as $k => $v) 
     { 
      if ($v != '') 
      { 
       $headers[$k] = $v; 
      } 
     } 
     // 4. Remove the first index and leave the others to be used as the value 
     $a = array_slice($a, 1); 
     // 5. Make an empty array 
     $array = array(); 
     // 6. Lets loop the values 
     foreach ($a as $k => $v) 
     { 
      $i = 0; 
      // then loop the headers then for each headers lets get the values 
      // from variable $a based on how many the headers are. So we increment. 
      foreach ($headers as $key => $value) 
      { 
       $array[$k][$value] = $v[$i]; 
       $i++; 
      } 
     } 
     return $array; 
     fclose($handler); 
    } 
    /** 
    * CSV_parser::toTable() 
    * 
    * @param string $width 
    * @param integer $border 
    * @param integer $spacing 
    * @param integer $padding 
    * @param string $class 
    * @param mixed $id 
    * @return 
    */ 
    public function toTable($width = '100%', $border = 1, $spacing = 0, $padding = 5, 
     $class = 'mytable', $id = null) 
    { 
     $this->width = $width; 
     $this->class = $class; 
     $this->spacing = $spacing; 
     $this->padding = $padding; 
     $this->border = $border; 
     $this->id = $id; 

     $table = '<table width="' . $this->width . '" class="' . $this->class . 
      '" cellspacing="' . $this->spacing . '" cellpadding="' . $this->padding . 
      '" id="' . $this->id . '" border="' . $this->border . '">'; 
     // 1. Lets create some table headers 
     $table .= '<thead><tr>'; 
     foreach ($this->toArray() as $key => $value) 
     { 
      $headers = $value; 
     } 
     $headers = array_keys($headers); 
     foreach ($headers as $th) 
     { 
      $table .= '<th>' . $th . '</th>'; 
     } 
     $table .= '</tr></thead>'; 
     // Lets create the table body 
     $table .= '<tbody>'; 
     foreach ($this->toArray() as $key => $value) 
     { 
      $table .= '<tr>'; 
      foreach ($value as $val) 
      { 
       $table .= '<td>' . $val . '</td>'; 
      } 
      $table .= '<tr>'; 

     } 
     $table .= '</tbody>'; 
     $table .= '</table>'; 
     return $table; 

    } 
    /** 
    * CSV_parser::toJSON() 
    * 
    * @return 
    */ 
    public function toJSON() 
    { 
     return json_encode($this->toArray()); 
    } 
    public function toMYSQL($table_name = 'table_name') 
    { 
     $str = ''; 
     $the_array = $this->toArray(); 
     foreach($the_array as $array) 
     { 
      $k = implode(',',array_keys($array)); 
      $v = "'".implode("','",array_values($array))."'"; 
      $str .= "INSERT INTO $table_name($k) VALUES($v)\n"; 
     } 
     return $str; 
    } 

} 

사용법 :

$data = new CSV_parser('C:\wamp\www/sample.csv'); 
echo '<code>'; 
echo $data->toJSON(); 
echo '</code>'; 
echo $data->toTable(); 
echo '<pre>'; 
    echo $data->toMYSQL('',TRUE); 
echo '</pre>'; 
echo '<pre>'; 
    print_r($data->toArray()); 
echo '</pre>';