Have a working SQL statement:
my $q_it = $dbh->prepare("SELECT customdata.Field_ID,
customdata.Record_ID,
customdata.StringValue
FROM customdata
WHERE customdata.Field_ID='10012' && (StringValue LIKE '1%' OR StringValue LIKE '2%' OR StringValue LIKE '9%');
");
I have written a very simple Perl script for my client to run on their server/db. I could not test it directly, but I passed my code to their DBA:
$q_it->execute();
open (MYFILE, '>>data.txt');
while (my @row=$q_it->fetchrow_array)
{
print MYFILE $row[0].$row[1].$row[2];
}
close (MYFILE);
$q_it is just a normal SQL Select statement. I would assume the data.txt will contain many records(rows). However, surprisingly, it return the results in a single column, but many rows like:
100012
100012
...
100012
315941
315667
...
315633
2011-06
2011-06
...
2011-06
There are just about correct no. of rows for “100012”, the “31”values and the date strings. Ideally, it should be
100012 315941 2011-06
100012 315667 2011-06
100012 315633 2011-06
Could it be something I did wrong in my Perl or is this because their MySQL database has different structures?
Thanks for the help!
I would guess that you are looking at a previous attempt to dump the database. To get all values of the first column, followed by all values of the second etc. requires a very different program from the one you have shown.
Don’t forget that you are opening the file for append, which will leave any old data at the start of the file. I would have thought an open for write would be appropriate here, as the output from failed attempts is of little value.
I would also check the status of the
openusingApart from that, unless you have set
$\to a newline, you need to terminate your printed output with a newline to separate the records. It is also easier to writerather than mention each of the fields explicity.