Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm trying to insert data into mysql database using perl without succes.

i get the following error :

Name "main::DATA" used only once: possible typo at write.pl line 10. readline() on unopened filehandle DATA at write.pl line 10.

please,what am I doing wrong?

my script:

#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh=DBI->connect('DBI:mysql:database=test;host= localhost','root','mypassword',{RaiseError =>1,AutoCommit=>1},); + my $sql='INSERT INTO foo(Item1,Item2)VALUES(wahed,jouj)'; my $sth=$dbh->prepare($sql); while(<DATA>){ chomp; my @vals=split /\s+/, $_; $sth->execute(@vals); }

Replies are listed 'Best First'.
Re: perl and mysql
by moritz (Cardinal) on Apr 22, 2010 at 10:17 UTC

    Perl complains about reading from DATA because you have no __DATA__ section in your program. Where do you think Perl should take the data from if you don't provide any?

    Also you probably want VALUES(?, ?) in your SQL. See the DBI documentation.

    Perl 6 - links to (nearly) everything that is Perl 6.
      thank's moritz it works