A programmer's paradise created by the twist of deliberated fantasies, and actions of a determined imagination.
Follow ME:
www.linkedin.com
...
Our world is now compressed, made tiny, and is traveling inside its axis called the "network". Her images are displayed in the screen of a PC monitor, and inside, people can meet there ... Through my programs and applications.

Add to Google
Single-Batch Multi Uploader (FLASH)
The extended way of normal upload. You can select multiple files that you can browse from a single or multiple directories. All files that a ...

Perl CGI & MySQL

Greetings, let me share you something about Perl & MySQL.

First things to know before you can work with MySQL databases in Perl is to ensure that the Perl's DBI and DBD-mysql modules are installed.

Installation of Perl modules / packages can be achieved easily by using ActivePerl - a software that can be found here : http://www.activestate.com/activeperl/.

Creating your MySQL module in Perl:
TIP: This is how we create a Class in Perl. 

When creating a Perl Module, the file name and the package name should be the same. And the extension should be pm.

So in this example, our Class should be saved as DBMySQL.pm.
package DBMySQL;

# CREATE THIS CLASS'S CONSTRUCTOR
sub new {
my ($class, $database, $userid, $password) = @_;

my $self = {

_database => $database,
_userid   => $userid,
_password => $password,
_dsn      => "DBI:mysql:database=" . $database

};

bless $self, $class;
return $self;
}

# OPEN A CONNECTION TO THE DATABASE
sub open() {

my ($self) = @_;
my $dbh = DBI->connect($self->{_dsn}, $self->{_userid}, $self->{_password});
return $dbh;

}
1;
Creating your display page in Perl: TIP: The first line of your display page should specify the correct path to where Perl is currently installed in your machine. When using a Web Server, the default path should be #!/usr/bin/perl. You can name your file to any names with cgi or pl as it's main extension. Thus, in this file we can call it topics.cgi or topics.pl.
#!"C:\Program Files\xampp\perl\bin\perl.exe"

use CGI;
use DBI;
use strict;
use DBMySQL;

print CGI::header();

my $db = new DBMySQL("perl_forum", "root", "");
my $mysql = $db->open();

my $query = $mysql->prepare("SELECT `title`,`content`,`dt_created` FROM `topics`");
$query->execute();

print "We got " . $query->rows . " shouts and still counting ...<br><br>";

my $html_form = "";

while(my @row = $query->fetchrow_array()) {

	my($title, $content, $date) = @row;
	print $title . "<br />" . $date . "<br />" . $content . "<br><br>";

}
$query->finish();

# DISPLAY FORM TEMPLATE
print $html_form;