Skip to content

Instantly share code, notes, and snippets.

@jacobdam
Created August 14, 2013 04:48
Show Gist options
  • Save jacobdam/6228087 to your computer and use it in GitHub Desktop.
Save jacobdam/6228087 to your computer and use it in GitHub Desktop.
require 'mysql2'
p Mysql2::VERSION # Make sure mysql2 version >= 0.3.12
Encoding::default_internal = Encoding::UTF_8
Encoding::default_external = Encoding::UTF_8
s = 'Test emoji 💝' # text with emoji character
c = Mysql2::Client.new(username: 'root', database: 'test', encoding: 'utf8mb4')
c.query("INSERT INTO test(`text`) VALUES('#{c.escape(s)}')")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment