【发布时间】:2012-06-18 01:23:52
【问题描述】:
以下是我的应用程序的代码 sn-p。请记住,我对 PDO 非常非常陌生(例如,今天开始弄清楚)所以我有点困惑。
现在,if 语句返回 1,这是它应该的。这是意料之中的。但是,在我设置$node 之后发生了意想不到的事情:设置之后,它似乎是FALSE。什么?就在几行之前,我的 fetch() 尝试返回了预期值,所以我不知道发生了什么。
$sth = $dbh->prepare("
SELECT *, COUNT(*) AS num_rows
FROM flow
INNER JOIN flow_strings
USING(node_id)
WHERE
(
parent = 0
OR parent = :user_flow
)
AND source = 0
AND string = :input
");
$sth->bindParam(':user_flow', $user->info->flow);
$sth->bindParam(':input', $input_sentence);
$sth->execute();
// If node exists.
if ($sth->fetch()->num_rows > 0)
{
// Get the information for the node.
$node = $sth->fetch();
[...] etc
我猜是光标向前移动了,然后就没有什么要读的了,所以返回了 FALSE。不过,当然有办法解决这个问题!当我运行$sth->fetch()->num_rows 时,我并不想改变任何东西——我只是想读取一个值。有解决方法吗?我在做一些奇怪的事情吗?我迷路了,哈哈。
谢谢! :)
编辑:
Notice: Undefined variable: node_count ... on line 56
// Retrieve all child nodes under $parent.
$node_query = $dbh->prepare("
SELECT *, COUNT(*) AS num_rows
FROM flow
WHERE parent = :parent
");
$node_query->bindParam(':parent', $parent);
$node_query->execute();
// If child nodes exist.
if ($node_count = $node_query->fetch() && $node_count->num_rows > 0) // Line 56
{
[...] etc
【问题讨论】:
-
你试过阅读文档吗?