Having trouble getting MySQL data returned

56 views Asked by At

I have a long Perl script that in other places returns MySQL table data successfully using binds:

$query2 = "SELECT tblExportFiles.CompID, CompEmail, export_id,  export_name, query, num_records, sample_rate, record_startnum, Description, Pull_Type, remote_CompID  FROM tblExportFiles INNER JOIN tblCustomers USING(CompID) WHERE done=0 ORDER BY export_id ASC  ;";
$sqlQuery2 = $dbh->prepare( $query2 );
$sqlQuery2->execute or die "can't execute the query: " . $sqlQuery2->errstr;

$sqlQuery2->bind_columns(
    \$CompID,      \$CompEmail,  \$export_id,  \$fileName,
    \$queryFile,   \$numRecords, \$sampleRate, \$recStartNum,
    \$description, \$qType,      \$remote_CompID
);

while ( $sqlQuery2->fetch ) { ... }

But when I do the same sort of query here, it fails to return any values but doesn't throw an error:

my $ftpQuerySQL = "SELECT  tblResellersData.http_address ,ftp_address, ftp_username, ftp_password, ftp_dir, http_name, tblResellerCustomers.CompEmail FROM tblResellersData,  tblResellerCustomers WHERE  tblResellerCustomers.User_ID = '$remote_CompID' AND tblResellersData.CompID = '$CompID' ;  ";
    print "FTP SQL = $ftpQuerySQL\n\n";

    $QueryFTP = $dbh->prepare( $ftpQuerySQL );
    $QueryFTP->execute() or die "can't execute the query: " . $QueryFTP->errstr;

    $QueryFTP->bind_columns(
        \$http_address, \$ftp_address, \$ftp_username, \$ftp_password,
        \$ftp_dir,      \$remote_name, \$CompEmail
    );

    $QueryFTP->fetch();

It throws warnings

Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 302.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 302.
 is a   located in
Use of uninitialized value $ftp_dir in scalar chomp at ./Cron_file_output.pl line 303.
Use of uninitialized value $http_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_username in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_password in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $ftp_dir in concatenation (.) or string at ./Cron_file_output.pl line 304.
Use of uninitialized value $remote_name in concatenation (.) or string at ./Cron_file_output.pl line 304.
RETURNED VALUES......., ,  , , , , [email protected]
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 310.

But when I ran the same SQL under phpMyAdmin, it gave this result:

http_address website's url  ftp_address     ftp_username    ftp_password    ftp_dir     http_name   
http://www.highpeaksbyway.com/  highpeaksbyway.com  [email protected] dataUUU666##)   pulls/  TEST ME 
1

There are 1 answers

0
Borodin On

What are lines 302, 304, and 310?

It looks like your criteria (the WHERE conditions) are failing, and the statement returns no records

What does $QueryFTP->fetch return? You need to check its status before you use it. That is the major difference between the code that you think "works" and your problem case

You need to check the values of $CompID and $remote_CompID before the execute. You should also use placeholders in the prepare call, and supply the values in execute