Results 1 to 2 of 2

Thread: Insert Problem

  1. #1
    Join Date
    Sep 2005
    Location
    Dallas, Texas
    Posts
    3

    Unanswered: Insert Problem

    I am using the following script with no results.

    DB: saddlebo_sbsongs
    TABLE: testdb

    my $dbh = DBI->connect("DBI:mysql:saddlebo_sbsongs:localhost","s addlebo_webuser","lfsb");



    my $dbh->do("INSERT INTO 'testdb'
    values (?,?,?,?,?)", 'NULL','robert','robert@law.com','8175556666','bas s');

    #$STH->execute # Execute the query
    # or die "Couldn't execute statement: " . $STH->errstr;

    my $dbh->execute();
    my $dbh->finish();

  2. #2
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Perhaps something like the following will do what you want:

    ripped and modified from working code

    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use DBI qw(:sql_types);
    
    use constant {
       DSN=>"dbi:mysql:testing:localhost",
       USERNAME=>"",    # Username
       PASSWORD=>"",    # Password
        };
    
       # Suppose, for example
       my($s_Field_1,$s_Field_2,$s_Field_3)=('A','B','C');
    
       my($o_dbh)=DBI->connect($s_DSN,$s_Username,$s_Password) or die "Unable to connect to the Database!\n";
       my($s_SQLStatement)="insert into $s_Tablename (Field_1,Field_2,Field_3) values (?,?,?)";
       my($o_sth)=$o_dbh->prepare($s_SQLStatement) or die $o_dbh->errstr();
       my($i);
       $o_sth->bind_param(++$i,$s_Field_1,SQL_VARCHAR);
       $o_sth->bind_param(++$i,$s_Field_2,SQL_VARCHAR);
       $o_sth->bind_param(++$i,$s_Field_3,SQL_VARCHAR);
       $o_sth->execute() or die $o_dbh->errstr();
       $o_dbh->disconnect();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •