[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Msql question



  a) Please don't use mSQL.  Use a free SQL database instead, like
     Postgresql.  Old versions of MySQL are said to be free as well,
     but not yet packaged for Debian.

  b) Please don't use the old Interface of MsqlPerl, use DBD::mSQL
     instead.  That way you can easily exchange the backend db by
     switching to DBD::mysql or DBD::Pg (or even DBD::Oracle if you
     like)

Robert H. Clugston wrote:
> Check your web server logs.
> 
> Normally use should use the DBI module:
> 
> use DBI;
> my $dbh = DBI->connect("DBI:msql:forum","server","password") or die "Can't
> connect to database: DBI->errstr\n";
> 
> the syntax for the DBI module is pretty close to the msql module if not the
> same (it was in hamm.)

Here's a short example for DBD::Pg:

sub dbconnect
{
    my $dbh;

    $dbh = DBI->connect("dbi:Pg:dbname=$config{'database'}");
    print "Cannot connect" if (!dbh);
    return $dbh;
}

[..]

    my $dbh = dbconnect();
    my $query;
    my $rc;
    my $sth;

    $query = "SELECT foo,bar FROM foobar WHERE foo = 'foo' OR bar = 'bar' ORDER by bar,foo ";

    $sth = $dbh->prepare($query);
    if ($sth) {
        $rc = $sth->execute;
        if ($rc > 0) {
            while (@row = $sth->fetchrow_array) {
                printf "%s is %s\n", $row[0], $row[1];
            }
        }
    }

Regards,

	Joey

-- 
Let's call it an accidental feature.  --Larry Wall


Reply to: