Created
May 21, 2018 13:00
-
-
Save saboyutaka/f2858e3551c1cf00a3c64a34dc382b93 to your computer and use it in GitHub Desktop.
MySQLにアクセス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
require 'mysql2-cs-bind' | |
# Mysqlドライバの設定 | |
db = Mysql2::Client.new( | |
host: 'localhost', | |
port: 3306, | |
username: 'root', | |
password: '', | |
database: 'sample', | |
reconnect: true, | |
) | |
result = db.xquery("SELECT * FROM infos") | |
infos = result.to_a | |
puts infos[0]["name"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gem install mysql2 mysql2-cs-bind
してください