Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'mysql'
- require 'fastercsv'
- my = Mysql::init()
- # You can do any SSL stuff before the real_connect
- # args: hostname, username, password, database
- my.real_connect("localhost", "root", "", "import")
- #my.query("DELETE FROM data")
- FasterCSV.foreach('import_data.csv', 'r') do |row|
- # No escaping here, because I trust the input file. You may not
- my.query("INSERT INTO data" + "(id, first_name, last_name, email)" + "VALUES (#{row[0]}, #{row[1]}," + "#{row[2]}, #{row[3]})")
- end
Add Comment
Please, Sign In to add comment