SQL查询错误:SQLSTATE[HY093]:参数号混合了命名参数和位置参数。

huangapple go评论68阅读模式
英文:

Query error: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

问题

"Does anyone know why my mySQL query gets this error? SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

try {
$sql = "UPDATE kunder SET fname=?, ename=?, user=? WHERE id = :id";
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':id', $_SESSION["user_id"]);
$data = array($fname, $ename, $user);
$stmt->execute($data);
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}"

英文:

Does anyone know why my mySQL query gets this error? SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

try {
                                $sql = &quot;UPDATE kunder SET fname=?, ename=?, user=? WHERE id = :id&quot;;
                                $stmt = $dbconn-&gt;prepare($sql);
                                $stmt-&gt;bindParam(&#39;:id&#39;, $_SESSION[&quot;user_id&quot;]);
                                $data = array($fname, $ename, $user);
                                $stmt-&gt;execute($data);
                            } catch (PDOException $e) {
                                echo $sql . &quot;&lt;br&gt;&quot; . $e-&gt;getMessage();
                            }

答案1

得分: 1

尝试以下翻译代码部分:

try {
    $sql = 'UPDATE kunder SET ' .
        'fname=:fname,' .
        'ename=:ename,' .
        'user=:user ' .
        'WHERE id = :id';
    $stmt = $dbconn->prepare($sql);
    $data = array(
        'fname' => $fname,
        'ename' => $ename,
        'user' => $user,
        'id' => $_SESSION["user_id"],
    );
    $stmt->execute($data);
} catch (PDOException $e) {
    echo $sql . "<br>" . $e->getMessage();
}

希望这对你有所帮助。如果你需要进一步的翻译或有其他问题,请随时提出。

英文:
try {
    $sql = &#39;UPDATE kunder SET &#39; .
        &#39;fname=:fname,&#39; .
        &#39;ename=:ename,&#39; .
        &#39;user=:user &#39; .
        &#39;WHERE id = :id&#39;;
    $stmt = $dbconn-&gt;prepare($sql);
    $data = array(
        &#39;fname&#39; =&gt; $fname,
        &#39;ename&#39; =&gt; $ename,
        &#39;user&#39; =&gt; $user,
        &#39;id&#39; =&gt; $_SESSION[&quot;user_id&quot;],
    );
    $stmt-&gt;execute($data);
} catch (PDOException $e) {
    echo $sql . &quot;&lt;br&gt;&quot; . $e-&gt;getMessage();
}

huangapple
  • 本文由 发表于 2023年3月31日 16:26:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75896373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定