David,
  Try something a bit different
===============================================
use DBI;

# Added:  This will probably break you in lots of
places,
# but use strict is worth it.
use strict;

# Strict on $infile
my $infile = "/cadfs8/sys/dnazary/mysql_test_data1";


# Strict on $dbh
my $dbh = DBI
->connect('DBI:mysql:database=dnazary_test:hostnamte=localhost',
'root', 'mysql');

open (IFH, $infile) or die ("Could not open input
file.");
foreach (<IFH>) {
        # Strict on @fields
        my @fields = split (/ /, $_);

        # Strict on $RowAffected  Also, just DEW-WHEAT
(Arnold Schwartzeinager accent)
        my $RowAffected = $dbh->do ("INSERT into infiles
(keynum,name,model)
VALUES('null','$fields[0]','$fields[1]')"); 
        
        print ("Updated $RowAffected Rows\n");
}   

close (IFH);

$dbh->disconnect();
===============================================
--- "Nazary, David" <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I am unable to insert data into MySql with following
> script:
> 
> #!/usr/bin/perl 
> use DBI;
> use Mysql;
> $infile = "/cadfs8/sys/dnazary/mysql_test_data1";
> $dbh = DBI
> ->connect('DBI:mysql:dnazary_test:localhost',
> 'root', 'mysql');
> open (IFH, $infile) or die ("Could not open input
> file.");
> foreach (<IFH>) {
> (@fields) = split / /, $_;
> $query = $dbh->prepare ("INSERT into infiles
> (keynum,name,model)
> VALUES('null','$fields[0]','$fields[1]')"); 
> $query->execute();
> }   
> close IFH;
> $dbh->disconnect();
> 
> The error I get is:
> DBD::mysql::st execute failed: Unknown column 'name'
> in 'field list' at ./mysql_write1.pl line 21, <IFH>
> line 1.
> 
> 
> However when I remove my column names in the INSERT
> command as below, it works.
> 
> $query = $dbh->prepare("INSERT INTO infiles
> VALUES('null','$fields[0]','$fields[1]')");
> 
> I have tried numerous variations of the code and all
> have failed. Yet every post on the web claims that
> it works.
> Any comments, suggestions would be much appreciated.
> 
> Thanks
> David
> 
> 
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


=====
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d s+:++ a C++ UL++ US+ P+++ L++ 
W+++ w PS PE t++ b+ G e r+++ z++++
------END GEEK CODE BLOCK------

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

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

Reply via email to