Link to home
Start Free TrialLog in
Avatar of sjaguar13
sjaguar13

asked on

Microsoft Access Database and PERL...Using the select tag?

I'm new to DBs and really, really suck at PERL. I need to have my database online. It has three columns, but only two will be displayed at this time. My question is, how do I get the two columns from Access to the web page? I tried looking for an answer, but all I found was:
SELECT *
FROM TABLE;

I know * is the column and TABLE is the table, but where do I go from there?
Avatar of rj2
rj2

To select only two fields you can use

SELECT Field1, Field2 FROM TABLE;
Avatar of sjaguar13

ASKER

So I have a cgi script like this:

#!C:\perl
SELECT Field1, Field2 FROM TABLE;
Print "Field1 = $Field1";
Print "Field2 = $Field2";
ASKER CERTIFIED SOLUTION
Avatar of rj2
rj2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
first to start using databases with perl you need to install the DBI module.

DBI stands for Database Interface.

first strat your Perl Package Manager, you should get a prompt like this

ppm>

type the following command

ppm> install DBI

this should install the perl DBI module

now you can start using the DBI module in your scripts. and before you start you must master the sql, it is pretty easy.

and then this link will be of help,
http://www.mysql.com/doc/P/e/Perl_DBI_Class.html
Ok, I can't get this to work. What is PPM? Because I don't think I have that. I use Apache with Windows 98...how do I install the DBI thing?
1. look for a file named "ppm.bat" in your perl/bin directory.
2. run that file.
3. ppm>install DBI.

Thats All
sjaguar13,
You have installed ActiveState Perl, right?
If not, download it from URL below and install it.
http://www.activestate.com/Products/Download/Get.plex?id=ActivePerl

After you have installed it, start up a DOS prompt, and type commands as shown below (as lexxwern suggested).
PPM is a tool that comes with ActiveState Perl you can use to install Perl modules. Press enter after each command
(after installing ActiveState Perl you should have path to ppm.bat).

ppm
install DBI
install DBD::ODBC
exit

Then enter control panel, doubleclick on ODBC, click on "System DSN" property sheet, then click button "Add".
Select "Microsoft Access Driver (*.mdb), and click "Finish".
Type "test" as data source name, click button "Select" and select the Access .mdb file you want to use. The .mdb file should be located below the root of the web server.

If you still have problems we need to know exactly what kind of problems you're having in order to help you. Include information about what have you done so far, and what kind of error message you get (if any).
sometime ppm might not work (well at least on my machine), try ppm3 instead.
If you are using a windows machine why not use IIS and ASP... Much simpler

Code:

<html>
<head>
      <title>Access Database</title>
</head>

<body>

<table border="1">
<%
'Create objects to connect to database
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.RecordSet")

'Connect to database and execute query
objConn.Open "ODBC Name Here"
objRs.Open "SELECT FieldName1, FieldName2 FROM TableName", objConn

'Loop through records
Do Until objRs.EOF
      Response.Write "<tr>"
      Response.Write "<td>"& objRs("FieldName1") &"</td>"
      Response.Write "<td>"& objRs("FieldName2") &"</td>"
      Response.Write "</tr>"
Loop

'Close connection to database
objRs.Close
objConn.Close

'Kill of objects
Set objRs = Nothing
Set objConn = Nothing
%>
<table>

</body>
</html>


Simple... Create a text file, put that code in it and then access it through its URL.
Sorry last comment should have been:

"Simple... Create a text file, put that code in it, save it as whatever.asp and then access it through its URL.