If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Insert Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-05, 15:54
butchseaman butchseaman is offline
Registered User
 
Join Date: Sep 2005
Location: Dallas, Texas
Posts: 3
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();
Reply With Quote
  #2 (permalink)  
Old 10-10-05, 21:32
senza_nome senza_nome is offline
Registered User
 
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();
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On