queries not getting executed?
am 21.08.2006 14:18:04 von rvbhute
This is my code.
#! C:\Perl\bin\perl.exe -w
use strict;
use DBI;
use CGI qw(:standard);
use CGI::Carp ;
use CGI::Carp 'fatalsToBrowser' ;
print header;
print start_html('IDS');
my $dbh = DBI->connect( 'dbi:Oracle:ilclpdv3',
'rbhute',
'rbhute',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";
print p('Connected');
my $sth = $dbh->prepare("select table_name from user_tables");
$sth->execute();
while (my ($table_name) = $sth->fetchrow_array()) {
print p("$table_name");
}
$sth->finish();
print p('Disconnected');
$dbh->disconnect();
It gives the following output.
Re: queries not getting executed?
am 21.08.2006 14:38:40 von jseger
Add some "or die" clauses to your prepare and execute statements, like
you did to your connect.
On 8/21/06, rohit bhute wrote:
> This is my code.
>
>
> #! C:\Perl\bin\perl.exe -w
>
> use strict;
> use DBI;
> use CGI qw(:standard);
> use CGI::Carp ;
> use CGI::Carp 'fatalsToBrowser' ;
>
> print header;
> print start_html('IDS');
>
> my $dbh = DBI->connect( 'dbi:Oracle:ilclpdv3',
> 'rbhute',
> 'rbhute',
> {
> RaiseError => 1,
> AutoCommit => 0
> }
> ) || die "Database connection not made: $DBI::errstr";
>
> print p('Connected');
>
> my $sth = $dbh->prepare("select table_name from user_tables");
> $sth->execute();
> while (my ($table_name) = $sth->fetchrow_array()) {
> print p("$table_name");
> }
> $sth->finish();
>
> print p('Disconnected');
> $dbh->disconnect();
>
>
> It gives the following output.
>
RE: queries not getting executed?
am 21.08.2006 15:41:12 von rjk-dbi
rohit bhute [mailto:rvbhute@gmail.com] wrote:
> [snip]
>
> Whih is correct. However, when I change the query to read any of the
> tables, it shows just "Connected" and "Disconnected".
>
> Any idea of where I'm going wrong?
You've showed us the code that works, but not the code that doesn't... :)
Are you sure the tables you're reading from aren't actually empty?
Ronald
Re: queries not getting executed?
am 22.08.2006 03:02:31 von rvbhute
Ronald J Kimball wrote:
> Are you sure the tables you're reading from aren't actually empty?
>
Thats it! I forgot to commit the changes in the sqlplus window. So the
'select' statements were working fine there, but obviously there was
nothing actually in the tables.
The only change in the code was the query - select user_name from
t_ids_mst_usr .
--
Rohit V. Bhute
http://blog.rvbhute.org