Sorry, I've tried searching, I still can't get it to work.
#!C:\Perl\bin
use strict;
use DBI;
my $fromHost = "someServer";
my $fromDB = "someDB";
my $fromTable = "someTable";
my @fromFields = ("Field 1", "Field 2", "Field 3");
my $fromDSN = "dbi:mysqlPP:database=$fromDB;host=$fromHost";
my $dbh = DBI->connect($fromDSN, "", "");
my $drh = DBI->install_driver("mysqlPP");
my $rs = $dbh->selectall_arrayref("SELECT '" . join("','", @fromFields
+) . "' FROM $fromTable");
$dbh->disconnect();
foreach my $myRow (@$rs) {
print "@$myRow\n";
foreach my $myElem (@$myRow) {
print "$myElem,";
}
print "\n";
}
This will print the following:
Field 1 Field 2 Field 3
Field 1,Field 2,Field 3,
It will repeat these two lines for each record in the table, but it will never return any data from table. I do admit, I need to know the field names (the hardcoded part will eventually be removed, and fields can be supplied at runtime), but I need to get to the data, too. What am I doing wrong, and in which document should I've found the answer?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.