Guest User

Untitled

a guest
May 21st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'mysql'
  4. require 'fastercsv'
  5.  
  6. my = Mysql::init()
  7. # You can do any SSL stuff before the real_connect
  8. # args: hostname, username, password, database
  9. my.real_connect("localhost", "root", "", "import")
  10.  
  11. #my.query("DELETE FROM data")
  12.  
  13. FasterCSV.foreach('import_data.csv', 'r') do |row|
  14. # No escaping here, because I trust the input file. You may not
  15. my.query("INSERT INTO data" + "(id, first_name, last_name, email)" + "VALUES (#{row[0]}, #{row[1]}," + "#{row[2]}, #{row[3]})")
  16. end
Add Comment
Please, Sign In to add comment