when I run the code it displays nothing. below is the work so far
#!C:/Ruby192/bin/ruby
require "dbi"
require 'cgi'
cgi = CGI.new
puts cgi.header
begin
# connect to the MySQL server
dbh = DBI.connect("DBI:Mysql:testdb:localhost",
"root", "root77")
sth = dbh.prepare("SELECT * FROM data")
sth.execute()
sth.fetch do |row|
printf "First Name: %s, Last Name : %s\n", row[0], row[1]
printf "Sex : %s\n", row[2]
printf "Salary :%s \n\n", row[3]
end
sth.finish
rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
# disconnect from server
dbh.disconnect if dbh
end
thanks


Sign In
Create Account


Back to top









