Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Question of SQL and an array

by ArmandoG (Sexton)
on Nov 27, 2007 at 18:25 UTC ( [id://653325]=note: print w/replies, xml ) Need Help??


in reply to Re: Question of SQL and an array
in thread Question of SQL and an array

Hi you almost got it is very simple but since english is my
second or third language is getting hard, look you almost
got it, I want to do this, from a MYSQL table call
PATENTES get ONLY the field PAT, to do this I have
to do this :
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"; }
so far so good, at this point I have @row->[0] that has all the data from the field PAT of the table PATENTES.

Now with these array I want to use it in another file this is a CSV datafile and it has a PAT field too, so I want to extract the data from this file using PAT and if posible to create a new CSV file with the name of the field PAT using INTO OUTFILE, I try to do this but did not work:
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()) { my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'cars', 'CSV', 'testperl.csv', 'ad_catalog'); my $sth = $dbh->prepare("SELECT * INTO OUTFILE @row->[0].csv FROM ca +rs WHERE pat = @row->[0]); $sth->execute(); }
Hope this is more exact

Replies are listed 'Best First'.
Re^3: Question of SQL and an array
by jZed (Prior) on Nov 27, 2007 at 18:38 UTC
    It's not your English that is confusing me, it's your perl :-). You are getting your $dbh's and $sth's mixed up -- you need to name them differently, so for example $m_dbh is your MySQL dbh and $a_dbh is your AnyData dbh. But I also still don't understand what your goal is. You want to get everything in the CSV file that has a PAT equal to a PAT in the MySQL database, right? Then what do you want to do with that data?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://653325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found