Try checking $DBI::err after each database statement. If $DBI::err is set, print out $DBI::errstr. This will help you find SQL commands that are failing.

 

For example…

 

$dbh->do(“some SQL command”)

if ($DBI::err) {

  die “$DBI::errstr\n”;

}

 

You might also try an insert manually from the mysql> client tool. This is often helpful in finding a mismatch between the column names specified in your script and the actual column names in you database.

 

cn


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eko Budiharto
Sent: Thursday, May 18, 2006 10:43 PM
To: [email protected]
Subject: error in inserting to mysql

 

hi,

I write a script that does extract data from a dbf file and insert the value into mysql. After I ran it, it does not insert the data into mysql.

 

the script:

 

#!/usr/bin/perl -w

use strict;
use DBI;

my ( $brg, $nama, $jenis, $stn, $hbeli, $maxi, $mini, $stn2, $isi, $hpp, $hbesar, $hkecil, $mvc, $lks, $sup, $merek, $part, $type, $nama2, $klink, $hp_std, $qprod, $qsales, $tgl_klr, $warna ) = "";

my $dbh = DBI->connect("DBI:XBase:h:\/fuboru\/dataIMS" ) or die $DBI::errstr;

my $sth = $dbh->prepare("select brg from hipdf02") or die $dbh->errstr();
$sth->execute();

while (my $row = $sth->fetchrow_arrayref() ) {
 #my ( $brg, $nama, $jenis, $stn, $hbeli, $maxi, $mini, $stn2, $isi, $hpp, $hbesar, $hkecil, $mvc, $lks, $sup, $merek, $part, $type, $nama2, $klink, $hp_std, $qprod, $qsales, $tgl_klr, $warna ) = @$row;
 
 my ( $brg ) = @$row;
 
 $dbh->do( "INSERT INTO hipdf02 (brg, nama, jenis, stn, hbeli, maxi, mini, stn2, isi, hpp, hbesar, hkecil, mvc, lks, sup, merek, part, type, nama2, klink, hp_std, qprod, qsales, tgl_klr, warna )
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )",
undef, $brg, $nama, $jenis, $stn, $hbeli, $maxi, $mini, $stn2, $isi, $hpp, $hbesar, $hkecil, $mvc, $lks, $sup, $merek, $part, $type, $nama2, $klink, $hp_std, $qprod, $qsales, $tgl_klr, $warna );


print "$brg, $nama, $jenis, $stn, $hbeli, $maxi, $mini, $stn2, $isi, $hpp, $hbesar, $hkecil, $mvc, $lks, $sup, $merek, $part, $type, $nama2, $klink, $hp_std, $qprod, $qsales, $tgl_klr, $warna\t\t transferred\n";

}

$dbh->disconnect();

 

do you mind if someone can tell me what is wrong with the code?

 

I am looking forward to a favorable reply from you. Thank you.


 


Feel free to call! Free PC-to-PC calls. Low rates on PC-to-Phone. Get Yahoo! Messenger with Voice

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to