PHP Classes

CSV to SQL database converter: Import data from a CSV file into a database

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 73%Total: 5,754 All time: 408 This week: 455Down
Version License Categories
csv2db 1.0.0GNU General Publi...PHP 5, Databases, Files and Folders
Description 

Author

This package can be used to import data stored in CSV files into a database.

The main class can import the data into a table named by imported CSV-file name. Table in database is like image of CSV file, query "DROP TABLE IF EXISTS `<CSV-filename>`" is called before table creation!

The types of the columns and other details can be defined in a separate configuration XML file. This package comes with one class that can parse and extract the configuration details.

The import class uses an external package to provide DBMS independent access to the database in order to store the imported data.

Picture of Michal Palma
Name: Michal Palma <contact>
Classes: 4 packages by
Country: Czech Republic Czech Republic
Age: 43
All time rank: 791 in Czech Republic Czech Republic
Week rank: 288 Down1 in Czech Republic Czech Republic Equal

Details

/* * * Class converts CSV content to DB table * @package Csv2Db * @date 2005-08-08 */ *Motivation - convert CSV files as table to database - as flexible as possible - easily and separately configured idealy by XML file *Dependencies: - PHP 5 needed - Class DbControl needed - You can find it at www.phpclasses.org in archiv of Author Michal Palma - Class Xml2Array needed - You can find it at www.phpclasses.org in archiv of Author Michal Palma - Class Csv needed - You can find it at www.phpclasses.org in archiv of Author Michal Palma *Install - fulfil dependencies higher - Check all includes in _preload.php - configure database connection and other in config.xml in DbControl package for task csv2db. (Actual DbControl/config.xml does contain it, You must only reconfigure connection parameters) - try "___case_of_use.php" - if You want to parse big table, you will must specify higher "max_execution_time" for longer script run in Csv2Db/config.xml. This attributes are exclusive for concrete table. *How to use it? First you must create an instance of Csv2Db class with essential parameters. - For example: $instance = new Csv2Db("test.csv", $separator = ";", $charset = "utf8", $useconfig = true). Then you must only call $instance->dbWrite(). If there is some problem, library will throw standard PHP5 exception. If not, You can call $instance->getRowsCount() for get how much rows did file contents. Thanks to DbControl class you can use any from supported Database platforms (in v1.3: MySQL, MSSQL, ODBC). You can choose between them by change attributtes in DbControl/config.xml whithout any change of code. All converting process is closed into transaction. *Projected improvements on next versions - performance optimalization Some cases of use are defined in ___case_of_use.php.

  Files folder image Files (8)  
File Role Description
Plain text file config.xml Data Configuration data
Plain text file Csv2Db.class.php Class Csv2Db class
Plain text file Csv2DbCfg.class.php Class Csv2DbCfg class
Plain text file Csv2DbInterface.class.php Class Csv2DbInterface class
Accessible without login Plain text file readmeFirst.txt Doc. Read me
Accessible without login Plain text file test.csv Data CSV file to testing
Plain text file _preload.php Aux. preload script
Accessible without login Plain text file ___case_of_use.php Example Case of use

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadcsv2db-2005-11-01.zip 7KB
Downloadcsv2db-2005-11-01.tar.gz 6KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
XML 2 Array Download .zip .tar.gz To read XML configuration Required
CSV managing class Download .zip .tar.gz To read CSV file Required
SQL databases interface Download .zip .tar.gz To write to database (any supported by it) Required
 Version Control Unique User Downloads Download Rankings  
 0%
Total:5,754
This week:0
All time:408
This week:455Down
 User Ratings  
 
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:81%StarStarStarStarStar
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:144