所以我有 4 个表,其中两个有空值,我认为这是“可捕获的致命错误:类变量对象无法转换为字符串”的原因。
我的桌子是
table1(dbo.FA_PC)
FAID(pk)
PCID(fk)
table2(dbo.PC)
PCID(PK)
PCCPUTypeID(fk)(some values are null/empty)
table3(dbo.PC_CPU_Type)
PCCPUTypeID(PK)
CPU
BrandID(fk)(some values are null/empty)
table4(Brand)
BrandID(PK)
Brand
所以我的代码和选择语句是这样的
<?php
$faidf=$_POST['faidf'];
ini_set("display_errors","on");
$conn = new COM("ADODB.Connection");
try {
$myServer = "WTCPHFILESRV\WTCPHINV";
$myUser = "sa";
$myPass = "P@ssw0rd";
$myDB = "wtcphitinventory";
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr);
if (! $conn) {
throw new Exception("Could not connect!");
}
}
catch (Exception $e) {
echo "Error (File:): ".$e->getMessage()."<br>";
}
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql_exp = "SELECT c.CPU, d.Brand
FROM dbo.FA_PC a
INNER JOIN dbo.PC b
on a.PCID = b.PCID
INNER JOIN dbo.PC_CPU_Type c
ON b.PCCPUTypeID = c.PCCPUTypeID
INNER JOIN dbo.Brand d
ON c.BrandID = d.BrandID
WHERE a.FAID = $faidf AND c.PCCPUTypeID is NOT NULL and c.BrandID is NOT NULL";
$rs = $conn->Execute($sql_exp);
echo "<tr><td>".$rs->Fields("Brand")."-".$rs->Fields("CPU")."</td>";
$rs->Close();
?>
是我的 where 语句错误,还是我的 select 语句有点偏离,或者是什么导致了“可捕获的致命错误:无法将类变量对象转换为字符串”的错误