in reply to Weird Problem with DBI

Ok, this is the Perl script:

#!/usr/bin/perl

use DBI;

$dbh = DBI->connect("dbd:mysql:test","username","password") or die "Error!";
$sth = $dbh->prepare("select * from test");

@res = $sth->fetchrow_array;

$all = join('',@res);

print $all;

$sth->finish;
$dbh->disconnect;

The error I get when connecting running the Perl script is:

Can't connect(dbd:mysql:test username password), no database driver specified and DBI_DSN env var not set at test.pl line 5.

Any ideas?

I really appreciate your help,
Ralph :)

Replies are listed 'Best First'.
Re: Re: Weird Problem with DBI
by PsychoSpunk (Hermit) on Jul 03, 2001 at 21:16 UTC
    perldoc DBD::mysql

    That being said, your DSN passed to connect isn't properly configured. DBD::mysql requires a different syntax in the connect statement requiring hostname and database instead of simply naming the database you wish to use.

    Assuming the mysql-server is on the same box as the script, try: $dbh = DBI->connect("dbi:mysql:database=test;hostname=localhost", "username", "password", {RaiseError => 1});

    The RaiseError is just good use of available attributes of the DBI. Read perldoc DBI for more and what they do.

    ALL HAIL BRAK!!!