简体   繁体   English

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

[英]Error HY093 with a MySQL Insert PDO Request

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 :这是我的表:表 PhpMyAdmin 屏幕截图

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 错误吗?

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

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.因 HY093 错误而失败。 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.我怀疑这是由从字符串到日期的隐式转换引起的,但尝试显式 STR_TO_DATE(format, sDate) 并没有解决它。 However if I quote all my placeholders in other queries with PDO::PARAM_STR value, it caused problems.但是,如果我使用 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,但它在混合中添加了另一个案例以帮助弄清楚发生了什么。

My issue was number of parameters didn't match number of placeholders.我的问题是参数数量与占位符数量不匹配。 Might be worth adding this to @aynber's answer可能值得将此添加到@aynber 的答案中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM