2017 © Pedro Peláez
 

library tableconverter

Table format converter

image

nagyatka/tableconverter

Table format converter

  • Friday, October 27, 2017
  • by nagyatka
  • Repository
  • 2 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

User documentation

To convert a table to another format you have to define 3 parameters:, (*1)

  • A decoder which tries to decode the original format
  • A coder which will generate the new table
  • An association rule which helps the converter to make an appropriate conversion
Converter::convert(Decoder $decoder, AssociationRule $associationRule, Coder $coder);

Simple examples

It inserts an xlsx file to mysql table using mysqli. It will use the xls header as column names of the mysql table:, (*2)

Converter::convert(new XlsxCodec("test_file.xlsx"), new SimpleAssociationRule(), new MysqliCodec($connection,"table_name"));

It inserts an php array to mysql table using mysqli. It will use the array keys as column names of the mysql table:, (*3)

$testArray = [
    ["col1" => 2, "col2" => 3, "col3" => "yes"],
    ["col1" => 1, "col2" => 222, "col3" => "apple"],
];
Converter::convert(new ArrayCodec($testArray), new SimpleAssociationRule(), new MysqliCodec($connection,"table_name"));

Codecs

Codec classes contain the coder and decoder implementation for an appropriate format., (*4)

ArrayCodec, (*5)


$testArray = [ ["col1" => 2, "col2" => 3, "col3" => "yes"], ["col1" => 1, "col2" => 222, "col3" => "apple"], ]; //If you use ArrayCodec as Decoder you have to specify the input associative array. $arrayDecoder = new ArrayCodec($testArray); //If you use ArrayCodec as Coder you can leave the constructor blank. $arrayCoder = new ArrayCodec();

CsvCodec, XlsCodec, XlsxCodec, (*6)


//If you use CsvCodec, XlsCodec or XlsxCodec as Decoder you have to specify the input file name. $csvDecoder = new CsvCodec("test_file.csv"); $xlsDecoder = new XlsCodec("test_file.xls"); $xlsxDecoder = new XlsxCodec("test_file.xlsx"); //If you use CsvCodec, XlsCodec or XlsxCodec as Coder you have two options. //First option: You specify the file name, thus the coder will write out the table in that file. Converter::convert(new CsvCodec("test_file.csv"), new SimpleAssociationRule(), new XlsxCodec("new_test_file.xlsx")); //Second option: If you don't set the filename parameter, the coder will return with the file as a string. $xls = Converter::convert(new CsvCodec("test_file.csv"), new SimpleAssociationRule(), new XlsxCodec());

MysqliCodec, (*7)


//If you use MysqliCodec as Coder, you have to set the mysqli connection and the name of the table $db = new mysqli('localhost', 'user', 'pass', 'demo'); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } $mysqliCoder = new MysqliCodec($db,"table_name"); //If you use MysqliCodec as Decoder, you have to more options. Firstly, you can use as same as in Coder. It will //select the whole table with all column. $mysqliDecoder = new MysqliCodec($db,"table_name"); //Another option is that you write an arbitrary sql query. In this case, you can leave the table name empty. $mysqliDecoder = new MysqliCodec($db,"","SELECT * FROM table_name WHERE col1 > 5 OR col2 = 44"); $mysqliDecoder2 = new MysqliCodec($db,"","SELECT * FROM table_name JOIN table_name2 ON (table_name.id = table_name2.id)");

AssociationRule

The Versions

27/10 2017

dev-master

9999999-dev https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

27/10 2017

1.0.5

1.0.5.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

14/07 2017

1.0.4

1.0.4.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

07/03 2017

1.0.3

1.0.3.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

03/03 2017

1.0.2

1.0.2.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

07/02 2017

1.0.1

1.0.1.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx

29/01 2017

1.0.0

1.0.0.0 https://github.com/nagyatka/tableconverter

Table format converter

  Sources   Download

Apache-2.0

The Requires

 

by Attila Nagy

csv xls array converter mysql xlsx