我们有一个旧的应用程序使用Perl-5.8.5.8可以正常工作,但在Perl-5.8.8上不再有用,我确定它只是一个简单的改变,但我无法找到它。
DBD::mysql::st execute failed: Unknown column 'stores.id' in 'on clause' at /var/www/cgi-bin/app/list.cgi line 70
这是第70行的背景
my $sth=$dbh->prepare($sql);
$sth->execute(); ################Line 70
这是完整的程序
#!/usr/bin/perl
do "share.pl";
sub get_propertytable {
my ($id, $devicename) = @_;
my $content = "<table><tr><th colspan=2>$devicename $id</th></tr>";
my $sql = "SELECT propertytypes.propertyname, deviceproperties.propertyvalue FROM deviceproperties INNER JOIN propertytypes ON deviceproperties.propertytype = propertytyp$
my $sthq = $dbh->prepare($sql);
$sthq->execute();
$sthq->bind_columns(\$propname, \$propvalue);
while ($sthq->fetch()){
if ($propname !~ /"Connected"/){
$content .= "<tr><td>$propname</td><td>: $propvalue</td></tr>";}
}
$content .= "</table>";
}
sub get_storetable {
my $id = @_[0];
my $content = "<table><tr><th colspan=2>Store $id</th></tr>";
my $sql = "SELECT storename,address,postcode,phoneno FROM stores WHERE id=$id";
my $sthq = $dbh->prepare($sql);
$sthq->execute();
my ($storename, $address, $postcode, $phoneno);
$sthq->bind_columns(\$storename, \$address, \$postcode, \$phoneno);
$sthq->fetch();
$address =~ s/,/<br>/g;
my $content = "<table><tr><th colspan=2>$storename</th></tr>";
$content .= "<tr><td valign=top>Address :</td><td>$address</td></tr>";
$content .= "<tr><td>Post Code :</td><td>$postcode</td></tr>";
$content .= "<tr><td>Phone No :</td><td>$phoneno</td></tr>";
$content .= "</table>";
}
sub get_franchisetable {
my $id = @_[0];
if ($id){
my $content = "<table><tr><th colspan=2>Franchise $id</th></tr>";
my $sql = "SELECT contactname,company,contactno,email FROM Franchisees WHERE id=$id";
my $sthq = $dbh->prepare($sql);
$sthq->execute();
my ($contactname, $company, $contactno, $email);
$sthq->bind_columns(\$contactname, \$company, \$contactno, \$email);
$sthq->fetch();
$address =~ s/,/<br>/g;
my $content = "<table><tr><th colspan=2>$company</th></tr>";
$content .= "<tr><td valign=top>Contact Name :</td><td>$contactname</td></tr>";
$content .= "<tr><td>Contact No :</td><td>$contactno</td></tr>";
$content .= "<tr><td>Email :</td><td>$email</td></tr>";
$content .= "</table>";
}
}
if ( valid_user() == 1 ) {
my $sql = "SELECT id,devicename FROM devicetypes";
my $sth=$dbh->prepare($sql);
$sth->execute();
$sth->bind_columns(\$id, \$devicename);
while ($sth->fetch()){
$devicetypes[$id] = $devicename;
}
$sth->finish();
my $sql = "SELECT stores.id, stores.storename, devices.id,devices.devicetype,tradingpartner.name,tradingpartner.id
FROM stores,storetradingpartner,tradingpartner
LEFT JOIN devices ON devices.store = stores.id
WHERE stores.id = storetradingpartner.storeid
AND tradingpartner.id = storetradingpartner.partnerid
ORDER BY tradingpartner.name,stores.storename,devices.devicetype,devices.id";
my $sth=$dbh->prepare($sql);
$sth->execute(); ################# Line 70
#$sth->bind_columns(\$storeid, \$store, \$deviceid, \$devicetype, \$tradingpartner, \$partnerid);
print "Content-type: text/html
<body link='#000000' vlink='#000000' alink='#000000'>
<script type=\"text/javascript\" src=\"/clit/wz_tooltip.js\" language='javascript'>
</script>
<SCRIPT SRC=\"/clit/getpropertytable.js\">
</SCRIPT>
<script language='javascript' type=\"text/javascript\">
function hidediv(thediv) {
if (document.getElementById(thediv).style.display == 'none'){
document.getElementById(thediv).style.display = 'block';
} else {
document.getElementById(thediv).style.display = 'none';
}
return 0;
}
//</script>
<font face=arial>
<h1>Asset List</h1>
<a href=index.cgi>Back to ticket list</a>
<br><br>
答案 0 :(得分:9)
我怀疑你已经升级到更新的MySQL服务器版本。
这样的查询:
FROM stores, storetradingpartner, tradingpartner
LEFT JOIN devices ON devices.store = stores.id
我认为,的解析方式不同于MySQL 4.0 5.0.12。您应该避免将隐式连接(例如table, table2, table3
)与显式连接(例如LEFT JOIN
)混合使用。
试试这个:
FROM stores
INNER JOIN storetradingpartner ON stores.id = storetradingpartner.storeid
INNER JOIN tradingpartner ON tradingpartner.id = storetradingpartner.partnerid
LEFT JOIN devices ON devices.store = stores.id
ORDER BY...
http://dev.mysql.com/doc/refman/5.5/en/join.html:
以前,逗号运算符(,)和JOIN都具有相同的优先级,因此连接表达式t1,t2 JOIN t3被解释为((t1,t2)JOIN t3)。现在JOIN具有更高的优先级,因此表达式被解释为(t1,(t2 JOIN t3))。此更改会影响使用ON子句的语句,因为该子句只能引用连接操作数中的列,并且优先级的更改会更改这些操作数的解释。
请注意,5.0.1和5.0.12中还有其他连接更改,以使MySQL更符合SQL标准,其中一些会导致返回行的差异,而不仅仅是产生错误,就像在这种情况下一样。 / p>