我正在改變我的方式,並將我的網站從使用mysql_query轉換爲PDO,我很難過。使用PDO從特定列和行中返回數據
之前,我會質疑我的數據庫和檢索特定的行這樣的特定列:
$getPhotos_query = "select * from resultsPhotos where fk_surveyID = 1 and fk_itemID = 123 order by resultPhotoID";
$getPhotos_result = mssql_query($getPhotos_query);
$thisPhoto1 = mssql_result($getPhotos_result, 0, 'resultPhotoFile');
$thisPhoto2 = mssql_result($getPhotos_result, 1, 'resultPhotoFile');
$thisPhoto3 = mssql_result($getPhotos_result, 2, 'resultPhotoFile');
現在我看到的錯誤在我的方式,並轉換爲PDO這樣
$getPhotos_query = $conn->prepare('select * from resultsPhotos where fk_surveyID = :surveyID and fk_itemID = :itemID order by resultPhotoID');
$getPhotos_query->execute(array('surveyID' => 1,'itemID' => 123));
$getPhotos_result = $getPhotos_query->fetchAll(PDO::FETCH_OBJ);
但現在我無法弄清楚如何從三個返回的行中檢索resultPhotoFile列。
'$ getPhotos_result [1] - > resultPhotoFile'很棒 –