【问题标题】:PDO Update Error: Invalid Parameter number - Parameter was not definedPDO 更新错误:参数编号无效 - 未定义参数
【发布时间】:2015-12-01 10:18:44
【问题描述】:

我已阅读有关此错误的所有主题:

带有消息“SQLSTATE[HY093]”的异常“PDOException”:参数号无效:未定义参数

但似乎找不到我出错的地方。

我的代码:

$pdo->executePrepared([
        "query"=> "UPDATE users SET studie = :studie, studieland = :studieland, typestudie = :typestudie,
                   jaaropleiding = :jaaropleiding, onderwijsinstelling = :onderwijsintelling,
                   biografie = :biografie, voornaam = :voornaam, achternaam = :achternaam,
                   geslacht = :geslacht, geboortedatum = :geboortedatum WHERE userid = :userid LIMIT 1",
        "params"=>[
            ":studie"=> addslashes($studie_correct),
            ":studieland"=> $_POST['studieland'],
            ":typestudie"=> $typestudie,
            ":jaaropleiding"=> $_POST['jaaropleiding'],
            ":onderwijsinstelling"=>addslashes($_POST['onderwijsinstelling']),
            ":biografie"=> addslashes($_POST['biografie']),
            ":voornaam"=> addslashes($_POST['voornaam']),
            ":achternaam"=> addslashes($_POST['achternaam']),
            ":geslacht"=> $_POST['geslacht'],
            ":geboortedatum"=> $_POST['geboortedatum'],
            ":userid"=> $userid
        ]
    ]);

所有参数都有一个值,所以它们都被定义了。

我已经做了很多这样的陈述,它们都很好,但我不知道这里出了什么问题。

感谢任何帮助。

【问题讨论】:

  • 发布您的完整代码,包括您的数据库连接
  • 您确定所有这些变量都已设置吗?也许您正在发送一些 NULL 值,这被认为是未发送的参数?
  • 是的,我确定,我会跟踪日志中的所有内容,它们都已填满。

标签: php pdo parameters


【解决方案1】:

我认为你正在使用Phalcon\Db\Adapter\Pdo\Mysql?只需删除数组键中的":"。仅从参数数组中删除它们,而不是从查询字符串中删除。

$pdo->executePrepared([
        "query"=> "UPDATE users SET studie = :studie, studieland = :studieland, typestudie = :typestudie,
                   jaaropleiding = :jaaropleiding, onderwijsinstelling = :onderwijsintelling,
                   biografie = :biografie, voornaam = :voornaam, achternaam = :achternaam,
                   geslacht = :geslacht, geboortedatum = :geboortedatum WHERE userid = :userid LIMIT 1",
        "params"=>[
            "studie"=> addslashes($studie_correct),
            "studieland"=> $_POST['studieland'],
            "typestudie"=> $typestudie,
            "jaaropleiding"=> $_POST['jaaropleiding'],
            "onderwijsinstelling"=>addslashes($_POST['onderwijsinstelling']),
            "biografie"=> addslashes($_POST['biografie']),
            "voornaam"=> addslashes($_POST['voornaam']),
            "achternaam"=> addslashes($_POST['achternaam']),
            "geslacht"=> $_POST['geslacht'],
            "geboortedatum"=> $_POST['geboortedatum'],
            "userid"=> $userid

关于 Phalcon PDO 的文档:https://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo_Mysql.html

【讨论】:

  • 我不知道。我在别人的项目中工作,所有使用的查询都需要重写为这些 executePrepareds。但正如我在原始帖子中提到的那样,我已经用键中的“:”做了很多,它们工作得很好。
  • 尝试不使用 ':' 并告诉我...这很棘手,因为 execute 使用 ':' 但 Phalcon 的 executePrepared 不使用。
  • 你为什么不尝试使用prepare 然后executePrepared 就像他们在此处的文档示例中使用它的方式一样:docs.phalconphp.com/en/latest/api/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-04
相关资源
最近更新 更多