0

我有这个代码:

 $sql = "SELECT personid FROM accountpersonmap WHERE accountid = :accountid; ";
 $array = array(
    'accountid' => $eachRow['accountid']
 );
 $sth = $dbh->prepare($sql);
 $sth->execute(array(':personid' => $personid))
 echo $personid;

我只想要personid好吗?我用谷歌搜索但没有找到我要找的东西。

谢谢

4

2 回答 2

0

你不需要谷歌,但需要教程。这是一个:https ://stackoverflow.com/tags/pdo/info

要获得价值,您必须获取它。

此外,从这个变量来看$eachRow['accountid'],您似乎需要在其他查询中使用 JOIN,而不是在循环中运行这个。

更新。

正如我上面所说,你需要一个教程
不仅仅是一个货物崇拜的例子,而是一个学习和理解如何使用 PDO 的教程。例如,如何从 PDO 获取错误。仔细一看,您的代码中有一个愚蠢的错字:

 WHERE accountid = :accountid;
                   ^^^^^^^^^^^

 $sth->execute(array(':personid' => $personid))
                      ^^^^^^^^^^

如果配置正确,PDO 应该会报告它。

于 2013-10-18T07:28:17.150 回答
0

类似的东西应该工作

$sql = "SELECT personid FROM accountpersonmap WHERE accountid = :accountid ";
$sth = $dbh->prepare($sql);
$sth->execute(array(':accountid' => $eachRow['accountid']));
$personid = $sth->fetchColumn();
echo $personid;
于 2013-10-18T07:29:01.510 回答