gpt4 book ai didi

php - SQLSTATE[42000] : Syntax error or access violation: 1064 PDO

转载 作者:行者123 更新时间:2023-11-29 06:39:31 27 4
gpt4 key购买 nike

我每次使用我的 Mysql PDO 类时都会得到这个:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? WHERE ?' at line 1

代码如下:

function mysql_execute_safe_search($table, $where, $query){
global $db;

try{
$preparedQuery = $db->prepare("SELECT * FROM ? WHERE ?");

$preparedQuery->execute([$table, $where, $query]);
return $preparedQuery->fetchAll(PDO::FETCH_ASSOC);
}

catch(PDOException $Exception){

echo $Exception->getMessage();

return;
}
}

我是这样执行的:

$search_query = mysql_execute_safe_search("people", "name", "Nathan");

最佳答案

不能绑定(bind)表名:

$preparedQuery = $db->prepare("SELECT * FROM yourtable WHERE ?");

关于php - SQLSTATE[42000] : Syntax error or access violation: 1064 PDO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336549/

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