fgsl/csvextractor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fgsl/csvextractor

Composer 安装命令:

composer require fgsl/csvextractor

包简介

component to extract data from CSV files to SQL database tables

README 文档

README

CSV file extractor for relational database tables

Extrator de arquivos CSV para tabelas de banco de dados relacional

Installation / Instalação

composer require fgsl/csvextractor

Configuration / Configuração

Configuration file / Arquivo de configuração

Copy the file config.php.dist as config.php and fill with the name of CSV file and the database connection parameters.

Copie o arquivo config.php.dist como config.php e preencha com o nome do arquivo CSV e com os dados de conexão com o banco de dados

Decorator

Create a class that implements the interface CsvExtractorInterface with the treatment for CSV file data and the statement INSERT for the table.

Crie uma classe que implemente a interface CsvExtractorInterface com o tratamento de dados do arquivo CSV e o comando INSERT para a tabela.

Example / Exemplo:

<?php

use Fgsl\CsvExtractorInterface;

class DecoratorMunicipios implements CsvExtractorInterface {
    /**
     * Value treatment and definition of INSERT statement
     */
        public function getValues(array $row): string
        {
            $values = "'" . $row[11]  . "'," . // CODIGO_MUNICIPIO
            "'" . str_replace("'","\'",$row[12]) . "'" . ',' . // NOME_MUNICIPIO
            "'" . $row[0] . "'" . ',' . // CODIGO_UF
            "'" . $row[1] . "'" . ',' . // NOME_UF
            $row[4]; // CODIGO_IBGE 
            return $values;
        }
    /**
     * General implementation: 
     * $values = getValues($row);
     * return "INSERT INTO (...) VALUES ($values)";
     */
        public function getSqlStatement(array $row): string
        {
                $values = $this->getValues($row);
                $sql = "INSERT INTO municipios(CODIGO_MUNICIPIO, NOME_MUNICIPIO, CODIGO_UF, NOME_UF, CODIGO_IBGE) VALUES ($values)";
                return $sql;
        }
}

Use / Uso

Create a script PHP that imports the Composer autoload.php, instances the class CsvExtractor and calls the method extractData.

Crie um script PHP que importe o autoload.php do Composer, instancie a classe CsvExtractor e chame o método extractData.

Example / Exemplo:

?php
include 'vendor/autoload.php';
include 'DecoratorMunicipios.php';

use Fgsl\CsvExtractor;

$csvExtractor = new CsvExtractor(include 'config.php',new DecoratorMunicipios());
$csvExtractor->extractData();

This script it that must be executed to extract the data from CSV file to database table.

Este script é que será executado para extrair os dados do arquivo CSV para a tabela do banco de dados.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2021-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固