mysql - 返回 MySQL 数据时遇到问题

标签 mysql perl bind dbi

我有一个很长的 Perl 脚本,它在其他地方使用绑定(bind)成功返回 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 ) { ... }

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

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 

最佳答案

第 302、304 和 310 行是什么?

您的条件(WHERE 条件)似乎失败,并且该语句未返回任何记录

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

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

中提供值

关于mysql - 返回 MySQL 数据时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41420765/

相关文章:

java - 什么是安全的 java applet 通信方式 -> MySQL

java - 从其他语言(如 Java、PHP、Perl、Python 等)调用 C/C++ 代码的最佳方式是什么?

perl - 如何在Perl中将文件与目录区分开?

perl - perl 信号 INT 的问题

javascript - 当用户更具体地填写输入时更新表选项

迄今为止的 MySQL 字符串(通用)

python - Tkinter 文本标记范围从开始和结束索引值从 wordstart 到 wordend?

c++ - std::bind 与指向函数对象的指针

php - 在列值表结构中搜索

c++ - 未指定绑定(bind)