#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Exeter, Devon, UK
    Posts
    1
    Rep Power
    0
    Hi everyone. I'm new to this forum and very new to PERL - in fact I have no knowledge of it at all so please excuse my ignorance.

    I've written a script for a client in ASP that connects to a database and pulls out a few values depending on a number entered in a HTML form element. It's dead straight forward, just about half a dozen lines of code.

    I've since found out that the server this script was to reside on doesn't support ASP, only CGI/PERL and I'm stuck. If anyone thinks they could help replicate my script in PERL I'd be very grateful. As yet I don't know whether I'm going to be paid for this job but if I am, I'll go 50/50 with you.

    What I'd basically like to know is can PERL be used to connect to a MS Access Database on an Apache Server? If so, is it easy and can it do something like the ASP script below?

    Please email me if you want the full source code and an example Access database.

    Thanks in advance.

    Head8k

    ----------

    <%@ Language = VBscript %>
    <%
    Dim passedVar, showInfo, infoSQL, objConn

    'This variable is comes from the referring page
    passedVar=Request.Form("ID")

    'use the Primary key for the query.

    infoSQL="SELECT FinTime, Forename, Surname FROM runners WHERE StartNo='" & passedVar & "'"

    set objConn = Server.CreateObject("ADODB.Connection")

    objConn.Open ("driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("mydatabase.mdb"))

    set showInfo=objConn.execute(infoSQL)

    %>

    <html>
    <head>
    <title></title>
    </head>
    <body onLoad="self.focus()">
    <p>This page will contain other page elements, I'll format it later.

    Finishing Time:
    <%= showInfo(0) %><br>

    Forename:
    <%= showInfo(1) %><br>

    Surname:
    <%= showInfo(2) %><br>
    </body>
    </html>

    ----------
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    82
    Rep Power
    14
    Well, I dont know if you would really want to use access with apache. Does the situation require it? Is it a large (greater than 3 tables, more than 1000 records) database? If not, there are workarounds. Send me some mail at josh_schoof@yahoo.com.

    The perl would look something like this:


    #!/perl

    use CGI;
    use YourDBPackage;
    $query = new CGI;
    $app = new YourDBPackage;

    my $passedVar;
    my $showInfo;
    my $infoSQL;
    my $objConn;


    $passedVar = $query->param(ID);

    $infoSQL = "SELECT FinTime, Forename, Surname FROM runners WHERE StartNo='$passedVar'";

    $objConn = $app->Recordset($infoSQL);

    @showInfo = $recset->fetchrow;

    print <<HTML;

    <html>
    <head>
    <title></title>
    </head>
    <body onLoad="self.focus()">
    This page will contain other page elements, I'll format it later.

    Finishing Time:
    $showInfo[0]

    Forename:
    $showInfo[1]

    Surname:
    $showInfo[2]
    </body>
    </html>

    And so forth. The only consideration is the "YourDBPackage" bit. I usually make
    up a .PM file with some handy DB functions in it, like the Recordset one seen
    above. That function looks like:

    sub Recordset {
    my ($self, $sqlStr) = @_;
    my $recset = $db->prepare($sqlStr);
    if ($recset) {
    $recset->execute;
    return $recset;
    }
    else {Error("",$DBI::errstr)}
    }

    Just set up your DB connection as "$db" and let er rip.

    Josh

    [This message has been edited by JSchoof (edited August 16, 2000).]

    [This message has been edited by JSchoof (edited August 16, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Yes, you should use something like mysql database for a *nix server.

IMN logo majestic logo threadwatch logo seochat tools logo