From: Michael Neumann Date: 2001-07-17T21:33:31+09:00 Subject: [ruby-talk:17989] Re: CGI->DB angelo.bettati@agip.it wrote: > Hi ML, > I have a problem: I' d like to create a simple file.CGI which extracts, > with a query, some fileds of DB made with Access97. > As server I' ve installed, on Win95, Apache. > Which are the line codes to do this? > Thanks in advance !! > Bye Install and use Ruby's DBI. See RAA section Library/Database -> DBI or http://www.ruby-projects.org/dbi Note for ADO (ActiveX Data Objects) as used below you need Win32OLE installed. Alternatively use the ODBC database driver -> you need to compile and install Ruby/ODBC. #### require "dbi" require "cgi" cgi = CGI.new sql = cgi["sql"][0] # SQL to execute. Security hole !!! print cgi.header("text/html") puts %{ } # create before an ODBC entry for your database you wanna access. # I assuming that it's name is "db" DBI.connect("dbi:ADO:db", "", "") do |dbh| dbh.execute(sql) do |sth| # output header puts "" sth.column_names.each {|i| puts "" } puts "" # output rows sth.each do |row| puts "" row.each {|col| puts "" } puts "" end end end puts %{
#{i}
#{col}
} Store this in your cgi-bin directory and execute it like http://localhost/cgi-bin/test.cgi?sql=SELECT+*+FROM+table which should show a HTML table as result containing the rows of the query. Code may contain some errors, I've not tested it! Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de