Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "mysql2"
- class MyDatabase
- def initialize
- @client = Mysql2::Client.new(
- :host => "localhost",
- :username => "root",
- :password => "yourpassword",
- :database => "sinatra"
- )
- end
- def select_all_komedian
- @hash = Hash.new
- @array = Array.new
- @query = @client.query("SELECT * FROM komedian ORDER BY id")
- @query.each do |a|
- @hash = {:id => a['id'], :nama => a['nama']}
- @array << @hash
- end
- return @array.to_json
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement