Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 08:47 am EST

Geeklog Forums

Useful tool - CSV to MySQL

Page navigation


droc

Anonymous
http://csv2sql.com/
 Quote

Agilefuse Consulting

Anonymous
angelic
http://www.agilefuseconsulting.co.cc/development/csvtomysql/

this is my tool. i developed the tool using html5 and file api. please take note that this only works on firefox and google chrome browser(latest version). also large data to import requires large time to complete, and also may cause memory limit error. so please use the tool with care. thanks.
 Quote

alexpran

Anonymous
seems most online tools have been taken down or dont work, but found I found this basic (and free) site convertcsvtomysql.com

seems limited but was enough for my needs, i think its still in dvelopment too
 Quote

thiyagi

Anonymous
thanks man..
 Quote

Erel Segal Halevi

Anonymous
Here is a PHP function that does the trick:
Text Formatted Code

function csv_file_to_mysql_table($source_file, $target_table, $max_line_length=10000) {
        if (($handle = fopen("$source_file", "r")) !== FALSE) {
                $columns = fgetcsv($handle, $max_line_length, ",");
                foreach ($columns as &$column) {
                        $column = str_replace(".","",$column);
                }
                $insert_query_prefix = "INSERT INTO $target_table (".join(",",$columns).")\nVALUES";
                while (($data = fgetcsv($handle, $max_line_length, ",")) !== FALSE) {
                        while (count($data)<count($columns))
                                array_push($data, NULL);
                        $query = "$insert_query_prefix (".join(",",quote_all_array($data)).");";
                        mysql_query($query);
                }
                fclose($handle);
        }
}
 
 Quote

sewerewes

Anonymous
This function won't work unless you've got your own function for quote_all_array() - that isn't a built-in PHP function. This works pretty well:
Text Formatted Code

function quote_all_array($arr)
{
        foreach ($arr as $k=>$v)
        {
               
                $returnArr[$k] = ($v) ? '"'.str_replace('"','\"',$v).'"' : "NULL" ;
        }      
        return $returnArr;
}
 
 Quote

Status: offline

MyJuliet

Forum User
Newbie
Registered: 08/23/11
Posts: 1
Please give me the correct link to your article, so I can use it. I have the same problem.
 Quote

Andreas Herz

Anonymous
Hi,

maybe the phpBlocks lib can solve the export/inport of CSV files in a more
smart way like Googles AppInventor. You can change the export format in an
Click&Point manner. Like Google AppInventor or the programming IDE Scratch
from the MIT.

phpBlocks is GPL and can be downloaded from the WebSite. Worth a look for dyn.
PHP formular and exports.

Common Demos: http://www.freegroup.de/software/phpBlocks/demo.html
Link to example: http://www.freegroup.de/test/editor/editor.php?xml=demo_sql.xml

Greetings

Andreas

 Quote

Anonymous Geek

Anonymous
For anyone wondering what was on the original mysqlDBU site... here it is in the internet archive http://web.archive.org/web/20100912102607/http://www.sqldbu.com/eng/sections/tips/mysqlimport.html it was a web-based solution Rolling Eyes
 Quote

Richard

Anonymous
If you would like to pre-validate and rollback on errror - you might like check out this post/tip on CSV import from Excel to MySQL

http://leansoftware.net/tabid/123/g/posts/t/17/How-to-validate-and-upload-CSV--comma-seperated-value--data-to-a-database.aspx

Could save you some time - this is a professional tool - free for 60 days
 Quote

Page navigation

All times are EST. The time is now 08:47 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content