[英]SQL error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
[英]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.