Always use placeholders, this should help...

my @abfrage = $sth->fetchrow_array;

# build placeholders based on num of fields
my $placeholders;
$placeholders .= ($placeholders ? ",?" : "?") for (@abfrage);

my $sth2 = $dbh->prepare("INSERT INTO board $placeholders");
$sth->execute(@abfrage);

The problem probably is that you are trying to insert varchar data and you
aren't quoting it.  This will take care of that for you.

Rob

-----Original Message-----
From: Theuerkorn Johannes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 26, 2002 9:00 AM
To: [EMAIL PROTECTED]
Subject: getting data from one table, putting it into another...


Hi there, again one (probably simple) question:

I have two databases and want to put the data from one table into the same
table in the other database...
Doing it like follows up gives me the right values, (like i can see from the
later Output) but doesnt write into the second table... Any suggestions? Its
Probably a problem from the array i guess...

Greets Johannes

#/usr/lib/perl -w
#
#
#Script um Teres Datenbank auszulesen un Daten in Direx zu schreiben
#


# Compilerpragma strict um keine Fehler zu machen :-)
use strict;
# Benutzung der Perl-Module CGI und DBI
use CGI;
use DBI;

my $user = "root";
my $pwd = "";

# connect to databases
my $dbh = DBI->connect( 'dbi:mysql:DiREx',$user,$pwd)||
     die "Kann keine Verbindung zum MySQL-Server aufbauen: $DBI::errstr\n";
my $dbh2 = DBI->connect ( 'dbi:mysql:dirextest',$user,$pwd)||
        die "Kann keine Verbindung zum MySQL-Server aufbauen:
$DBI::errstr\n";

# prepare sql query
# Handle Objekt wird zurueckgeliefert

my $sth = $dbh->prepare( "SELECT * FROM board where serial='CN+/P4226666'" )
||
     die "Kann Statement nicht vorbereiten: $DBI::errstr\n";

# execute query
$sth->execute ||
     die "Kann Abfrage nicht ausfuehren: $DBI::errstr\n";

#put values into an array
my @abfrage = $sth->fetchrow_array;

#prepare insert of values from the array in second database

my $sth2 = $dbh->prepare("INSERT INTO board @abfrage");

#execute insert
$sth->execute||
                die "Kann Abfrage nicht ausfuehren: $DBI::errstr\n";
                
while ( my @ergebnis = $sth->fetchrow_array ){
   # Im Array @ergebnis steht nun ein Datensatz
   #print "<LI>".$ergebnis[1]." ".$ergebnis[2]." ".$ergebnis[3]."
".$ergebnis[4]. "\n";
        print "@ergebnis\n";
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to