无法返回MySQL数据

时间:2017-01-02 02:30:46

标签: mysql perl bind dbi

我有一个很长的Perl脚本,在其他地方使用绑定成功返回MySQL表数据:

$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 ) { ... }

但是当我在这里执行相同类型的query时,它无法返回任何值,但不会抛出错误:

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();

它会发出警告

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......., ,  , , , , j@adki87.com
Use of uninitialized value $ftp_address in concatenation (.) or string at ./Cron_file_output.pl line 310.

但是当我在phpMyAdmin下运行相同的SQL时,它给出了这个结果:

http_address website's url  ftp_address     ftp_username    ftp_password    ftp_dir     http_name   
http://www.highpeaksbyway.com/  highpeaksbyway.com  data@highpeaksbyway.com dataUUU666##)   pulls/  TEST ME 

1 个答案:

答案 0 :(得分:1)

第302,304和310行是什么?

看起来您的条件(WHERE条件)失败,并且该语句不返回任何记录

$QueryFTP->fetch返回什么?您需要在使用之前检查其状态。这是您认为“有效”的代码与您的问题案例之间的主要区别

您需要在$CompID之前检查$remote_CompIDexecute的值。您还应该在prepare调用中使用占位符,并提供execute

中的值