How can I insert array data into MySQL in Perl? -


I parse a text file with the script below.

How to insert array data in the MySQL table?

I have already learned the Perl MySQL DBI Connect method. And I can successfully connect to local MySQL db. I can create a table with the MySQL command line

  #! C: \ Perl \ bin \ perl.exe strict; Use warnings; While (& lt; data & gt;) {my @rocks = split (/ \ s + /, $ _); Fork Mary Rock (@ Rocks) {$ rock = "\ t $ rock"; Put a tab in front of each element of # $ rocks. = "\ N"; # Put a new line at the end of every print $ rock; }} __DATA__ ABCDEFGH  

I want to browse the table result I

 Item1 Item2 Itme3 Item4 A CDEFGH 

  Use strict; Use warnings; Use DBI; My $ dbh = dbi- & gt; Connect ('dbi: mysql: database = test; host = localhost', 'root', 'yOUR_PASSWORD', {raiseError => 1, AutoCommit => 1},); My $ sql = 'Foo (item 1, item 2, item 3, item 4) value (?,?,?,?)'; My $ sth = $ dbh- & gt; Ready ($ sql); While (& lt; data & gt;) {chomp; My @vals = split / \ s + /, $ _; $ Sth- & gt; (@vals) execution; } __END__ABCDEFGH  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -