3

这是我在 StackOverflow 上的第一个问题,您能否向我解释一下我做错了什么:我有这段代码(如下),但由于某种原因,我试图查看和调试,我不明白为什么 PDO 不是完成下面的请求,插入和回显的工作方式相同,有人可以告诉我发生了什么吗?我沮丧地把头发从头上扯下来。

    $q = "UPDATE content SET urlid=:url, title=:title, description=:desc, keywords=:key     WHERE urlid=:urlid";
    $query = $pdo->prepare($q);
    $query->execute(array(
        ':url'     => $urlid,
        ':title'   => $title,
        ':desc'    => $desc,
        ':key'     => $key,
        ':contloc' => $contloc,
        ':userid'  => $uid,
        ':urlid'   => $urlid
        //':content' => $content
    ));

我在 Apache 错误日志中收到以下警告:

[Thu Jul 12 21:07:13 2012] [error] [client 99.230.122.54] PHP Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /Library/Server/Web/Data/Sites/Default/addto2.php 在第 31 行,引用者:http://localhost/sample/4fff30aea1f20

4

1 回答 1

2
$q = "UPDATE content SET urlid=:url, title=:title, description=:desc, keywords=:key WHERE urlid=:urlid";
$query = $pdo->prepare($q);
$query->execute(array(
    ':url'     => $urlid,
    ':title'   => $title,
    ':desc'    => $desc,
    ':key'     => $key,
    ':urlid'   => $urlid
));

PDO complains because you are passing more arguments than you are using in your query. Or perhaps you meant to include more arguments in your query and you forgot?

于 2012-07-13T01:18:14.597 回答