http://www.perlmonks.org?node_id=16511

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My DBI script works correctly when run by a web server, but I get syntax errors when running it from the command line (Perl 5 and FreeBSD server). Here's the code:
use DBI; ($db) = DBI->connect('DBI:mysql:DatabaseName, $dbusername);
Here are the corresponding errors:
syntax error in file MyScript.cgi at line 66, next 2 tokens "use DBI" syntax error in file MyScript.cgi at line 82, next 2 tokens "->"
What's the problem?

Replies are listed 'Best First'.
Re: script using DBI won't run from command line but runs great thru browser. why?
by btrott (Parson) on Jun 06, 2000 at 03:02 UTC
    Sounds like you're running it w/ perl4 under the command line. How are you executing the file? Where's your perl? Do you have 2 versions installed?
Re: script using DBI won't run from command line but runs great thru browser. why?
by IndyZ (Friar) on Jun 06, 2000 at 05:22 UTC
    If I follow btrott correctly, you probanly have perl installed in two places, like perl4 in /bin/perl, and perl5 in /usr/bin/perl. try typing "whereis perl" and see where the binaries are.

    =Brian

Re: DBI script works on command line but not in browser
by codehopper (Initiate) on Mar 07, 2003 at 18:10 UTC
    use DBI;
    my $dbh = DBI->connect("DBI:mysql:databasename:server", "user","password")
        or die "Couldn't connect to database";