external map problem

New to mod_rewrite? This is a good place to start.

external map problem

Postby spower » Wed May 04, 2005 2:08 pm

I want to use an external map to access a DB. I am trying to take a variable from the query string and do a database lookup on it and use the result as part of the url. What I have works well, but only the first time.

in virtual host

RewriteCond %{QUERY_STRING} cPath=([^&;]*)
RewriteMap my-map prg:/path/to/map/map.pl
RewriteRule ^/(.*)/index.php$ http://xxx.xxx.xxx.xxx/${my-map:%1}-c-%1.html? [L,R=301]

---------------------
map.pl

#! /path/to/perl

use DBI;
use strict;

my ($x);
my ($nospc);
my ($dsn)="DBI:mysql:xxxxxxx:xxxxxxx";
my ($user_name)="xxxxxxxx";
my ($password)="xxxxxxxxxx";
my ($dbh, $sth);
my (@ary);

$|=1;
$dbh=DBI->connect($dsn,$user_name,$password)
or die "could not connect";

$x=<STDIN>;

$sth=$dbh->prepare("SELECT categories_name from categories_description where categories_id = $x");
$sth->execute();

while(@ary=$sth->fetchrow_array())
{
$nospc = join("\t",@ary),"\n";
$nospc =~ s/ /-/g;
$nospc =~ s/\//or/g;
print $nospc;
}

$sth->finish();

$dbh->disconnect;
exit(0);

this works, but only once per connection
so I tried this map.pl

#! /path/to/perl

use DBI;
use strict;

my ($x);
my ($nospc);
my ($dsn)="DBI:mysql:xxxxxxx:xxxxxxxx";
my ($user_name)="xxxxxxxx";
my ($password)="xxxxxxx";
my ($dbh, $sth);
my (@ary);

$|=1;
$dbh=DBI->connect($dsn,$user_name,$password)
or die "could not connect";

while($x=<STDIN>)
{
$sth=$dbh->prepare("SELECT categories_name from categories_description where categories_id = $x");
$sth->execute();

while(@ary=$sth->fetchrow_array())
{
$nospc = join("\t",@ary),"\n";
$nospc =~ s/ /-/g;
$nospc =~ s/\//or/g;
print $nospc;
}

$sth->finish();

$dbh->disconnect;
}
exit(0);

this just caused apache to lockup

there must be a way to accomplish this.
any ideas?
spower
 
Posts: 1
Joined: Wed May 04, 2005 1:53 pm

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 39 guests

cron