Help for this page

Select Code to Download


  1. or download this
    my $cmd = "INSERT INTO $table ($fields) VALUES ($placeholderList)";
    
  2. or download this
    #  Accepts a database handle, a table name, and a hashref
    #  of field names and values. Returns on success, otherwise
    ...
    sub addData
    {
      my ( $dbh, $table, $args ) = @_;
    
  3. or download this
      #  Get a comma separated list of the field names ..
      my $fields = join(',', keys %$args);
    ...
      #  Get a comma separated list of '?', one for each value
      #  ..
      my $placeholderList = join(',',('?') x @values);
    
  4. or download this
      #  Prepare the command and execute it with the array of
      #  values.
    ...
      $sth->execute(@values) or die $sth->error;
    
      return 0;     # Success!
    
  5. or download this
    #  Accepts a database handle, a table name, and a hashref
    #  of field names and values. Returns on success, otherwise
    ...
    
      return 0;     # Success!
    }