我想在PHP腳本中執行查詢。該查詢在我的MySQL客戶端中工作正常,但它似乎並沒有在我的代碼中工作。我正在使用PDO。我認爲它可能有一些限制,因爲它似乎可以很好地處理較簡單的查詢。奇怪的PDO MySQL問題
下面是該查詢:
SELECT D.status, D.createdBy, D.createDate, D.modifiedBy, D.modifiedDate,D.IPAddress, D.adminStatus, D.campus, D.buildingID, D.deviceShortName, D.distributionID, D.networkKey, D.deviceName, D.test, D.pkDevices, D.DNSRule, D.Domain, D.DNSOverride, D.noDNS, D.pkModel, DM.Model, DM.pkManufacturer, M.manufacturer FROM Devices AS D INNER JOIN DeviceModel AS DM ON D.pkModel = DM.pkModel INNER JOIN Manufacturer AS M ON DM.pkManufacturer = M.pkManufacturer WHERE D.status = '1' AND D.adminStatus = 'Active' ORDER BY D.deviceName
這裏就是我想它調用我的腳本:
$dbhDevices = newPDO('mysql:host='.$_SESSION['OpsDBServer'].'.ops.tns.its.psu.edu;dbname='.$_SESSION['OpsDB'], $_SESSION['yoM'], $_SESSION['aMa']);
$sqlDevices = "SELECT D.status, D.createdBy, D.createDate, D.modifiedBy,
D.modifiedDate, D.IPAddress, D.adminStatus, D.campus, D.buildingID,
D.deviceShortName, D.distributionID, D.networkKey, D.deviceName, D.test,
D.pkDevices, D.DNSRule, D.Domain, D.DNSOverride, D.noDNS, D.pkModel, DM.Model,
DM.pkManufacturer, M.manufacturer
FROM Devices AS D
INNER JOIN DeviceModel AS DM ON D.pkModel = DM.pkModel
INNER JOIN Manufacturer AS M ON DM.pkManufacturer = M.pkManufacturer
WHERE D.status = '1' AND D.adminStatus = 'Active' ORDER BY D.deviceName";
foreach ($dbhDevices->query($sqlDevices) as $rowDevices)
{
同樣,查詢並與MySQL客戶端。
腳本內發生了什麼?是否生成或輸出了任何錯誤? (如果您提供更多信息,您可以使人們更容易地獲得幫助。) – 2010-01-14 20:34:30
-1:「不起作用」永遠不是一個足夠的問題描述。 – hobodave 2010-01-14 21:40:16
只是問了一個明顯的問題,在你的問題中,newPDO是一個錯字嗎?它應該是新的PDO()來實例化類 – iangraham 2010-01-15 05:34:53