Php 使用PDO从特定列和行返回数据

Php 使用PDO从特定列和行返回数据,php,mysql,pdo,Php,Mysql,Pdo,我正在改变我的方式,将我的网站从使用mysql_query转换为PDO,我被难住了 在查询数据库并从以下特定行检索特定列之前: $getPhotos_query = "select * from resultsPhotos where fk_surveyID = 1 and fk_itemID = 123 order by resultPhotoID"; $getPhotos_result = mssql_query($getPhotos_query); $thisPhoto1 = mss

我正在改变我的方式,将我的网站从使用mysql_query转换为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\u result[0]->resultPhotoFile
$getPhotos\u result[0]->resultPhotoFile
$getPhotos\u result[0]->resultPhotoFile
><

$thisPhoto1 = $getPhotos_result[0]->resultPhotoFile;
$thisPhoto2 = $getPhotos_result[1]->resultPhotoFile;
$thisPhoto3 = $getPhotos_result[2]->resultPhotoFile;
但是如果您更喜欢使用数组而不是对象,可以使用

$getPhotos_query->fetchAll();
相反,它默认为PDO::FETCH_

您可以查看以找到最适合您的fetch_样式

但是如果您更喜欢使用数组而不是对象,可以使用

$getPhotos_query->fetchAll();
相反,它默认为PDO::FETCH_

您可以查看以找到最适合您的fetch_样式

但是如果您更喜欢使用数组而不是对象,可以使用

$getPhotos_query->fetchAll();
相反,它默认为PDO::FETCH_

您可以查看以找到最适合您的fetch_样式

但是如果您更喜欢使用数组而不是对象,可以使用

$getPhotos_query->fetchAll();
相反,它默认为PDO::FETCH_

您可以查看以找到最适合您的fetch_样式