php 带有 MySQL 插入 PDO 请求的错误 HY093

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17027112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:08:35  来源:igfitidea点击:

Error HY093 with a MySQL Insert PDO Request

phppdo

提问by Baha?ka

After reading all others questions about the HY093, I open this one to figure out why I've got this message too.

在阅读了有关 HY093 的所有其他问题后,我打开了这个问题以弄清楚为什么我也收到了这条消息。

Here is my table : Table PhpMyAdmin screenshot

这是我的表: Table PhpMyAdmin screenshot

And here is my request : (Where $conn is my PDO connection)

这是我的请求:(其中 $conn 是我的 PDO 连接)

$sql = $conn->prepare("INSERT INTO Sites (Email,URL,Title,Description,PageRank,Rewrite,MetaDesc,Origin,BackLink,nbBackLink,RssTitle,RssAddress,SocAddress,SocPostalCode,SocCity,SocCountry,SocTel,Offer,Status,nbHit)
                         VALUES (:Email,:URL,:Title,:Description,:PageRank,:Rewrite,:MetaDesc,:Origin,:BackLink,0,:RssTitle,:RssAddress,:SocAddress,:SocPostalCode,:SocCity,:SocCountry,:SocTel,:Offer,:Status,0)");
$sql->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$pageRank = new GooglePageRank($_POST["site_url"]);

$sql->bindParam(":Email",$_POST["submail"],PDO::PARAM_STR);
$sql->bindParam(":URL",$_POST["site_url"],PDO::PARAM_STR);
$sql->bindParam(":Title",$_POST["site_title"],PDO::PARAM_STR);
$sql->bindParam(":Description",$_POST["site_desc"],PDO::PARAM_STR);
$sql->bindParam(":PageRank",$pageRank->PageRank,PDO::PARAM_INT);
$sql->bindParam(":Rewrite",stringToRewrite($_POST["site_title"]),PDO::PARAM_STR);
$sql->bindParam(":MetaDesc",$_POST["site_desc"],PDO::PARAM_STR);
$sql->bindParam(":Origin",$_POST["site_country"],PDO::PARAM_STR);
$sql->bindParam(":BackLink",$_POST["site_backlink"],PDO::PARAM_STR);
$sql->bindParam(":RssTitle",$_POST["site_rss_title"],PDO::PARAM_STR);
$sql->bindParam(":RssAddress",$_POST["site_rss_addr"],PDO::PARAM_STR);
$sql->bindParam(":SocAddress",$_POST["soc_addr"],PDO::PARAM_STR);
$sql->bindParam(":SocPostalCode",$_POST["soc_cp"],PDO::PARAM_STR);
$sql->bindParam(":SocCity",$_POST["soc_city"],PDO::PARAM_STR);
$sql->bindParam(":SocCoutry",$_POST["soc_pays"],PDO::PARAM_STR);
$sql->bindParam(":SocTel",$_POST["soc_tel"],PDO::PARAM_STR);

$offer = $_POST["offer"] == "premium" ? 1 : 0;
$status = $_POST["offer"] == "premium" ? 2 : 0;

$sql->bindParam(":Offer",$offer,PDO::PARAM_INT);
$sql->bindParam(":Status",$status,PDO::PARAM_INT);

$sql->execute();
var_dump($sql->errorInfo());
var_dump($sql->errorCode());

Any idea why I keep have an HY093 error?

知道为什么我一直有 HY093 错误吗?

回答by aynber

You have a typo in one of your bindParams, which means you have a mismatch in parameters:

您的 bindParams 中有一个拼写错误,这意味着您的参数不匹配:

$sql->bindParam(":SocCoutry",$_POST["soc_pays"],PDO::PARAM_STR);

should be

应该

$sql->bindParam(":SocCountry",$_POST["soc_pays"],PDO::PARAM_STR);

回答by Sanford Staab

Here's an interesting case I found:

这是我发现的一个有趣的案例:

Running this query:

运行此查询:

INSERT INTO videosubmissions (member_login, submission_date) VALUES (":login", ":submission-date")

Bound with:

绑定:

[ ':login',           $info['login'],   PDO::PARAM_STR ],
[ ':submission-date', $submission_date, PDO::PARAM_STR ]

works... but

工作......但是

INSERT INTO videosubmissions (member_login, submission_date) VALUES (:login, :submission-date)

fails with an HY093 error. I suspected this was caused by the implicit conversion from string to date but trying an explicit STR_TO_DATE(format, sDate) didn't fix it. However if I quote all my placeholders in other queries with PDO::PARAM_STR value, it caused problems.

因 HY093 错误而失败。我怀疑这是由从字符串到日期的隐式转换引起的,但尝试显式 STR_TO_DATE(format, sDate) 并没有解决它。但是,如果我使用 PDO::PARAM_STR 值引用其他查询中的所有占位符,则会导致问题。

I know this doesn't really answer the Q but it adds another case to the mix to help figure out what's up.

我知道这并没有真正回答 Q,但它在混合中添加了另一个案例以帮助弄清楚发生了什么。