gpt4 book ai didi

php - SQLSTATE[HY093] : Invalid parameter number: number

转载 作者:行者123 更新时间:2023-11-30 00:19:17 25 4
gpt4 key购买 nike

当我使用时

WHERE id_prekes = :prekes_id
AND tiekejas = :tiekejas

$prekes_id = 3;

$tiekejas = Silberauto,UAB;

我收到错误(SQLSTATE[HY093]:无效参数编号:数字),但是当我使用时

WHERE id_prekes = 3
AND tiekejas = "Silberauto, UAB"

错误消失了。我的脚本:

<?php
$tiekejas = $_GET['tiekejas'];
$prekes_id = $_GET['prekes_id'];

echo // "<script type='text/javascript'>alert('$tiekejas');</script>";

$username='root';
$password='pass';
try {
$conn = new PDO('mysql:host=localhost;dbname=univer', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT vnt_kaina
FROM tiekeju_prekes
INNER JOIN tiekejai ON tiekeju_prekes.id_tiekejo = tiekejai.id
WHERE id_prekes = :prekes_id
AND tiekejas = :tiekejas
');

$stmt->bindParam(':tiekejas', $tiekejas, PDO::PARAM_INT);
$stmt->bindParam(':prekes_id', $prekes_id, PDO::PARAM_INT);

$stmt->execute(array('tiekejas' => $tiekejas,'prekes_id' => $prekes_id));

while($row = $stmt->fetch()) {
echo $row['vnt_kaina']." LT ";
}
} catch(PDOException $e) {
echo 'KLAIDA: ' . $e->getMessage();
}

最佳答案

使用:

$stmt->bindParam(':tiekejas', $tiekejas, PDO::PARAM_STR);
$stmt->bindParam(':prekes_id', $prekes_id, PDO::PARAM_INT);

或者

$stmt->execute(array('tiekejas' => $tiekejas,'prekes_id' => $prekes_id));

还要注意 PDO::PARAM_ - $tiekejas 是一个字符串,因此您应该使用 PDO::PARAM_STR 而不是 PDO::PARAM_INT

关于php - SQLSTATE[HY093] : Invalid parameter number: number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com