簡體   English   中英

mysql 數據庫 SQLSTATE[42000]:語法錯誤或訪問沖突:1064 您的 SQL 語法有誤

[英]mysql database SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

我從這段代碼中得到錯誤我不知道如何弄清楚

<?php
    include "db.php";
    include "auth.php";
    if(isset($_GET["getlist"]))
    {
        $uid=$_GET["getlist"];
        
        $sql="SELECT * FROM devices WHERE brand_id=:uid ORDER BY id ASC";
        $query=$db->query($sql);
        $devices=$query->fetchAll(PDO::FETCH_OBJ);

    }
?>

由@lawrence-cherone 幫助完成

這是答案

<?php
    include "db.php";
    include "auth.php";
    if(isset($_GET["getlist"]))
    {
        
        try {
            $uid=(int)$_GET["getlist"];
            $sql=$db->prepare("SELECT * FROM devices WHERE brand_id = :uid ORDER BY id ASC");
            $sql->execute([':uid' => $uid]);
            $devices = $sql->fetchAll(PDO::FETCH_OBJ);
            } catch (Exception $e) {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
        }
    }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM