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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



blelump
New User

May 1, 2007, 3:56 PM

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

Hi!

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 ./aa.pl line 23.". I guess I closed every active handle (or not?)...


Code
#!/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";

$sth->finish;

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



blelump
New User

May 2, 2007, 2:02 AM

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

btw. if im doing something like that:

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

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


KevinR
Veteran


May 2, 2007, 3:08 PM

Post #3 of 4 (4544 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.
-------------------------------------------------


eWish
User

Aug 3, 2007, 8:34 AM

Post #4 of 4 (4427 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.

Code
 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);
$insert_->finish();


#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