错误的PDO插入:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配 [英] Error PDO insert: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

查看:69
本文介绍了错误的PDO插入:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PDO id_facebook(mysql bigint),名称(mysql varchar)和email(mysql varchar)插入,但无法解决此错误,PDO语法看起来正确,可以是什么?

I'm trying to insert with PDO id_facebook (mysql bigint), name(mysql varchar) and email(mysql varchar), but can not resolve this error, the PDO syntax looks correct, what can be?

public static function inserirUsuarioFacebook($id_facebook, $nome, $email)
{
    try
    {
        $pdo = Conexao::getInstance();

        $consulta = $pdo->prepare("INSERTO INTO usuario_facebook (id_facebook, nome, email) VALUES (:id_facebook, ':nome', ':email')");
        $consulta->bindParam(':id_facebook', $id_facebook, PDO::PARAM_INT);
        $consulta->bindParam(':nome', $nome, PDO::PARAM_STR);
        $consulta->bindParam(':email', $email, PDO::PARAM_STR);
        $consulta->execute();   
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}

推荐答案

您不引用占位符.这会将它们转换为字符串,而不是占位符:

You don't quote placeholders. That turns them into strings, not placeholders:

... VALUES(:id_facebook, :nome, :email)
                         ^----^-^-----^--- note the lack of quotes

是所有必需的

占位符的全部目的是消除引用/转义的任何需要.数据库引擎会为您完成所有这些工作.

The whole point of placeholders is to remove any need for quoting/escaping. The DB engine takes care of all that for you.

这篇关于错误的PDO插入:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆