CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: DBI:
a problem with $sth->finish


New User

May 1, 2007, 3:56 PM

Post #1 of 4 (9347 views)
a problem with $sth->finish Can't Post


Im pretty new in Perl and DBI as well. Below Im trying add smth to the database and actually it came down. The problem is always when I've been closed database I had got error like: "closing dbh with active statement handles at ./ line 23.". I guess I closed every active handle (or not?)...

#!/usr/bin/perl -T 

use DBI;
use strict;
use warnings;

my $dbh = DBI->connect("DBI:SQLite:dbname=baza.db", "", "",
{'AutoCommit' => 1, 'PrintError' => 1}) || die "error";

my $aa = "aaaafefaaaa";
my $bb = 'bbbbbbb';

my $sql = qq{INSERT INTO table};
$sql .= qq{ (indexx, a, b)};
$sql .= qq{ VALUES(NULL, ?, ?)};

my $sth = $dbh->prepare($sql);

$sth->execute($aa, $bb) || die "error, $DBI::errstr";


$dbh->disconnect || die "eeeeeeeee: $DBI::errstr";

New User

May 2, 2007, 2:02 AM

Post #2 of 4 (9335 views)
Re: [blelump] a problem with $sth->finish [In reply to] Can't Post

btw. if im doing something like that:

my $test=$dbh->do($sql, undef, $aa, $bb);

there is no error anymore. what im doing wrong with prepare, execute things then?


May 2, 2007, 3:08 PM

Post #3 of 4 (9322 views)
Re: [blelump] a problem with $sth->finish [In reply to] Can't Post

sorry, but I don't know. DBI is a real weakness for me.


Aug 3, 2007, 8:34 AM

Post #4 of 4 (9205 views)
Re: [blelump] a problem with $sth->finish [In reply to] Can't Post

I am sure that the user has resolved his/her issue by now. However, should someone else need the same information. Hopefully this will help.

 my %config_vars = (  
DBName => 'XXXX',
DBServerName => 'localhost',
DBUserName => 'XXXX',
DBPassword => 'XXXX'

my ($dbh, $data_source);

my $dataSource = 'DBI:mysql:' . $config_vars{DBName} . ':' . $config_vars{DBServerName};
my $dbh = DBI->connect( $dataSource, $config_vars{DBUserName}, $config_vars{DBPassword}, {RaiseError=>1});

# {RaiseError=>1} should capture your errors. Therefore, you do not need to have an
#|| die "error, $DBI::errstr"; for each of your requests to the db.

my $insert_ = $dbh->prepare("INSERT INTO table_name (column1, column2, column3) VALUES (?,?)");
$insert_->execute($params{'one'}, $params{'two'}, undef);

#If the value for a column is null you will use undef as the value.
#If the column is always NULL, then there is not a need to list it.
#Just list the columns you want inserted. Auto increment id's would be a good example of an always NULL or undef.

(This post was edited by eWish on Aug 3, 2007, 8:36 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives