Hi!
On 29.04.2011 09:45, Rai, Vikrant (GIS, Technology Services India) wrote:
Hello,
I am really struggling to connect to database, I am not sure how to
ensure that I HAVE DBI sintalled and if not then how to make it activate
it on my machine, I have perl installed but when I give the following
command on my command prompt then
perl -e 'use DBI; print $DBI::VERSION,"\n";' it gives following
errorcd c\
Can't find string terminator "'" anywhere before EOF at -e line 1.
On Windows, you need to use double quotes as the outermost quotes.
Windows does not understand single quotes. So try:
perl -e "use DBI; print qq[$DBI::VERSION\n];"
or, if you have a recent perl:
perl -MDBI -E "say $DBI::VERSION"
Upper and lower case is significant! -E enables say, with -e, say is not
available.
or just write the DBI version without a trailing newline:
perl -MDBI -e "print $DBI::VERSION"
or if you just want to know if *any* version of DBI is installed:
perl -MDBI -e 1
(No error: DBI installed. "Could not find ..." error message: DBI not
installed. Works for any module.)
Also when I am exccuting a database program it gives the following
highlighted error, any help on this will be higly appreciated...
#!/usr/bin/perl -w
use strict;
use dbi();
Wrong. Perl is case sensitive, but your underlying file system seems to
be case insensitive.
DBI must be written with upper case letters.
use lib;
"use lib" is useless without arguments.
my $dbh = dbi->connect('dbi:Oracle:****',
Once again, Perl is case sensitive. The class name is DBI, not dbi.
(Note that "dbi:Oracle:..." is correct.)
'****',
'****',
{
RaiseError => 1,
AutoCommit => 0
}
)|| die "Database connection not made:
$dbi::errstr";
The "|| die" construct is useless in combination with RaiseError set to
1, connect() will die on error by itself.
And again, Perl is case sensitive. The variable name is $DBI::errstr,
and you should not use it according to the DBI docs:
<URL:http://search.cpan.org/~timb/DBI-1.616/DBI.pm#DBI_Dynamic_Attributes>
my $sql = qq{ SELECT * FROM tab where rownum<3 };
Not related to your problem: Try to avoid SELECT *. It will cause
maintainance trouble, your least problem will be that it often fetches
far too much data.
Not related to your problem: Don't interpolate SQL, use placeholders.
my $sth = $dbh->prepare( $sql );
Not related to your problem: No need to pass a variable to prepare(),
you can use a string constant instead.
$sth->execute();
Not related to your problem: Pass values for placeholders to execute.
Not related to your problem: Where do you fetch the data?
$dbh->disconnect();
Name "dbi::errstr" used only once: possible typo at C:\seven.pl line 14.
Side effect of miss-spelling DBI as dbi.
Can't locate object method "connect" via package "dbi" at C:\seven.pl
line 7.
Ditto.
Alexander