
eWish
User
Aug 3, 2007, 8:34 AM
Post #4 of 4
(8164 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); $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)
|