[英]Fatal error: Uncaught PDOException: SQLSTATE[42000]
I get this error message, any help would be appreciated.我收到此错误消息,任何帮助将不胜感激。
(: ) Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation;
(: ) 致命错误:未捕获的 PDOException:SQLSTATE[42000]:语法错误或访问冲突; 1064 You have an error in your SQL syntax.
1064 您的 SQL 语法有错误。 check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 in index.php on line 96
检查与您的 MariaDB 服务器版本相对应的手册,以了解在第 96 行 index.php 的第 1 行的“)”附近使用的正确语法
(: ) PDOException: SQLSTATE[42000]: Syntax error or access violation;
(: ) PDOException: SQLSTATE[42000]: 语法错误或访问冲突; 1064 You have an error in your SQL syntax.
1064 您的 SQL 语法有错误。 check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 in index.php on line 96
检查与您的 MariaDB 服务器版本相对应的手册,以了解在第 96 行 index.php 的第 1 行的“)”附近使用的正确语法
This is the code:这是代码:
$centroId = $_SESSION['userId'];
$orderby= 'id DESC';
if (isset($_GET['orderby'])){
$orderby=filter_var($_GET['orderby'],FILTER_SANITIZE_STRING);
}
$where='';
$search='';
if (isset($_GET['cerca'])){
$search=filter_var($_GET['cerca'],FILTER_SANITIZE_STRING);
$where=' AND (cognome like "%'.$search.'%" OR nome like "%'.$search.'%" OR id='.$search.') ';
}
$perpage=3;
$sql='SELECT count(id) FROM utenti2 WHERE centroId=:centroId AND legge_privacy="SI" '.$where.'';
$result=$db->prepare($sql);
$result=$db->prepare($sql);
$result->bindParam(':centroId', $centroId, PDO::PARAM_INT);
$result->execute(); //line 96
尝试在id=$search
周围添加引号
$where=' AND (cognome like "%'.$search.'%" OR nome like "%'.$search.'%" OR id="'.$search.'") ';
turn off emulation mode: $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);关闭仿真模式: $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); it's work.
这是工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.