A
Arun Kumar
Hi,
I'm new to ruby and right now i'm trying out some examples involving
database access using the dbi module. This is my code...
#!/usr/local/bin/ruby -w
require 'dbi'
begin
con = DBI.connect("DBI:Mysql:Sample:localhost", "arunkumar", "123456")
stats = con.prepare("Select * from hello where first_name = ?")
stats.execute('arun')
if stats.fetch == nil
puts "No Records"
con.rollback
else
puts stats.fetch
end
rescue DBI:atabaseError => e
puts "Error: #{e.errstr}"
ensure
con.disconnect if con
end
If I use 'puts stats.fetch' before if the fetched data is displayed
properly. But if i use 'puts stats.fetch' inside if or else 'nil' will
be displayed even if there are matching records in the database. I dont
know why. Can anybody help me?????
Regards
Arun Kumar
I'm new to ruby and right now i'm trying out some examples involving
database access using the dbi module. This is my code...
#!/usr/local/bin/ruby -w
require 'dbi'
begin
con = DBI.connect("DBI:Mysql:Sample:localhost", "arunkumar", "123456")
stats = con.prepare("Select * from hello where first_name = ?")
stats.execute('arun')
if stats.fetch == nil
puts "No Records"
con.rollback
else
puts stats.fetch
end
rescue DBI:atabaseError => e
puts "Error: #{e.errstr}"
ensure
con.disconnect if con
end
If I use 'puts stats.fetch' before if the fetched data is displayed
properly. But if i use 'puts stats.fetch' inside if or else 'nil' will
be displayed even if there are matching records in the database. I dont
know why. Can anybody help me?????
Regards
Arun Kumar