简体   繁体   中英

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.

Here is my table :表 PhpMyAdmin 屏幕截图

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

$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?

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

$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. 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.

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

My issue was number of parameters didn't match number of placeholders. Might be worth adding this to @aynber's answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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