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: Re: [blelump] a problem with $sth->finish: Edit Log



eWish
User

Aug 3, 2007, 8:34 AM


Views: 4521
Re: [blelump] a problem with $sth->finish

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)


Edit Log:
Post edited by eWish (User) 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