PDA

View Full Version : CGI conversion


WebAddict
Tue 30th Jan '01, 2:19pm
Is it possible to take my cgi programs, and easily convert them to php? I want to get away from using my flat file system, and use more of the VB database. Idealy, I would like to get everything to revolve around VB on my site, including all of my current CGI apps...

JB007
Tue 30th Jan '01, 10:16pm
If your CGIs are too big, then I suggest using the DBI module with DBD::MySQL so that you can interact with vBulletin's MySQL database , a typical DBI script might look like this:

#!/usr/bin/perl -w
###################
# SQL Rocks!!!
###################

use strict;
use DBI;
use CGI; # If you need it
use CGI::Carp qw(fatalsToBrowser);

my $dbname = 'DataBase';
my $dbuser = 'you';
my $dbpass = 'password';
my $what_are_you_looking_for = 'Anything';

# Connection
my $dbh = DBI->connect("dbi:mysql:$dbname","$dbuser","$dbpass")
|| die("Unable to establish connection to MySQL for this reason: $DBI::errstr");

# Prepare query
my $sth = $dbh->prepare("select * from TABLE where id = ?");
$sth->execute("$what_are_you_looking_for");

while(my(@array_of_results) = $sth->fetchrow_array) {
# Do stuff ... anything .... @array_of_results contains
# each row's data
}

# Disconnect
$dbh->disconnect;

# That's it ...