每次我使用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");
答案 0 :(得分:2)
您无法绑定表名:
$preparedQuery = $db->prepare("SELECT * FROM yourtable WHERE ?");