dongzhi5587 2015-12-01 10:18
浏览 158

PDO更新错误:参数号无效 - 未定义参数

I have read all the topics on this error:

exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

but can't seem to find where I went wrong.

My code:

$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
        ]
    ]);

All of the parameters have a value so they are all defined.

I have done a lot of these kind of statements and they all went just fine, but I can't figure out what is wrong here.

Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • dougang5088 2015-12-01 10:31
    关注

    I take you are using Phalcon\Db\Adapter\Pdo\Mysql? Just remove the ":" in the array keys. Remove them only from the parameters array, not from the query string.

    $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
    

    Documentation on Phalcon PDO: https://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo_Mysql.html

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图