in reply to Question of SQL and an array

As mentioned, fetchrow_array() returns an array (not an array_ref), so access the first element as $row[0], not @row->[0]

Replies are listed 'Best First'.
Re^2: Question of SQL and an array
by ArmandoG (Sexton) on Nov 28, 2007 at 17:14 UTC
    Hi
    I try like you said
    #!?usr/bin/perl -w use DBI; my $dbh = DBI->connect("DBI:mysql:database=proyecto;host=localhost", "root", "xyz123", {'RaiseError' => 1}); my $sth = $dbh->prepare("SELECT PAT FROM patentes"); $sth->execute(); while ((my @row) = $sth->fetchrow_array()) { print "$row[0]\n"; my $a_dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $a_dbh->func( 'cars', 'CSV', 'testperl.csv', 'ad_catalog'); my $a_sth = $a_dbh->prepare("SELECT * INTO OUTFILE $row[0].csv FROM +cars WHERE pat = $row[0]"); $a_sth->execute(); }
    And giving me this error message:
    SQL ERROR: Bad table or column name 'INTO' is a SQL reserved word! DBD::AnyData::db prepare failed: SQL ERROR: Bad table or column name ' +INTO' is a SQL reserved word! [for Statement "SELECT * INTO OUTFILE 0447.csv FROM cars WHERE pat = +0447"] at finaltest.pl line 16. DBD::AnyData::db prepare failed: SQL ERROR: Bad table or column name ' +INTO' is a SQL reserved word! [for Statement "SELECT * INTO OUTFILE 0447.csv FROM cars WHERE pat = +0447"] at finaltest.pl line 16.
    can you help me please? thank you