ruhulfbr/csv-to-query

此软件包提供了一种简单工具,可以将CSV文件中的数据转换为SQL查询,用于数据库插入和创建表。

1.0.0 2024-04-29 12:26 UTC

This package is auto-updated.

Last update: 2024-09-29 13:23:43 UTC


README

此软件包提供了一种简单工具,可以将CSV文件中的数据转换为SQL查询,用于数据库插入。

安装

要安装此软件包,您可以使用 Composer

composer require ruhulfbr/csv-to-query

用法

<?php

require_once 'vendor/autoload.php';

use Ruhulfbr\CsvToQuery\Query;

$filePath = "example.csv";  // (String) Required, Absolute file path
$createQuery = false; // (Boolean) Optional, set true if need to generate table create query, Default is FALSE;
$tableName = ""; // (String) Optional, If tableName not provided then csv filename will be the table name, Default is an empty string;

// With Named argument
// $query = new Query($filePath, _TABLE_NAME: "your_table_name");
// $query = new Query($filePath, _CREATE_QUERY: true);

// Together
$query = new Query($filePath, $createQuery, $tableName);
print_r($query->generate());

响应

//Success
stdClass Object
(
    [type] => "success"
    [message] => "Query generated"
    [query] => "INSERT INTO `example` (`id`, `name`, `age`) VALUES ('1', '“Allis”', '24');
               INSERT INTO `example` (`id`, `name`, `age`) VALUES ('2', '\'Gwyneth’', '36');
               INSERT INTO `example` (`id`, `name`, `age`) VALUES ('3', 'Sashenka', '49')";
)

//Error
stdClass Object
(
    [type] => "error"
    [message] => "Invalid file path"
)

贡献

欢迎提交拉取请求。对于重大更改,请首先打开一个问题来讨论您想要更改的内容。

请确保根据需要更新测试。

此文档提供了关于安装和使用此软件包的明确说明。它包括每个参数的示例和解释,使用户能够轻松了解如何在项目中使用该软件包。