<?php namespace export; require 'medoo.min.php'; require 'config.php'; use medoo; use PDO; Export::$config = $config; Import::$config = $config; class Export { protected $table_head; protected $arr; protected $to_encoding; protected $from_encoding; protected $table_name; public static $config; function __construct($table_name, $x = '', $delimiter = ',', $to_encoding = 'UTF-8', $from_encoding = 'UTF-8') { //формируем шапку для сохраняемой таблицы,где x-- текст шапки //create head for table, where $x -- string whith head table $x = mb_convert_encoding($x, $to_encoding, $from_encoding); $this->arr = explode($delimiter, $x); $this->to_encoding = $to_encoding; $this->from_encoding = $from_encoding; $this->table_name = $table_name; } //connect to db private function create_db_connect() {
<?php // example use export require_once 'export.php'; require_once 'config.php'; use Export\Export as export; use Export\Import as import; //Constructor whith head table and other settings //in constructor input name tables, head table , string to converted,string convert from $export = new export('product', 'id,дата,хрень,product', 'Windows-1251', 'UTF-8'); //Insert filename and path , delimiter,enclosure to csv file $export->export('hello.csv', 'dir/', ';', '"'); // Using import file to database $import = new import(array('id', 'date', 'time', 'name_product', 'category', 'cost'), 'UTF-8', 'Windows-1251'); // arguments: headtable, filename,path, flag for read first line(1-no read),delimiter, enclosure $import->insert('product', 'hello.csv', 'dir/', 1, ';', '"'); //arguments:headtable,filename path, parameter (where id=$array[id])),flag for read first line $import->update('product', 'hello.csv', 'dir/', 'id', 1);