2017-01-02 113 views
0

有麻煩的MySQL數據返回

我有很長的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......., , , , , , [email protected] 
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 [email protected] dataUUU666##) pulls/ TEST ME 
+0

爲什麼要在'bind_columns'中傳遞引用? '$ CompId','$ CompEmail'等是什麼值? – mob

+0

@mob:推測是因爲這是正確的做法? – Borodin

回答

1

什麼是線302,304和310?

它看起來像你的條件(在WHERE條件)失敗,並且該語句返回任何記錄

什麼$QueryFTP->fetch回報?在使用它之前,你需要檢查它的狀態。這是您認爲「有效」的代碼與您的問題案例之間的主要區別

您需要檢查execute之前的$CompID$remote_CompID的值。您還應該在prepare調用中使用10佔位符,並提供execute中的值