参见英文答案 >
Can PHP PDO Statements accept the table or column name as parameter? 7个
我有一个应用程序,它为我的PHP传递一个变量(nomecardapioBD,它接收并记录在变量:nomecardapioBD),这是我想要选择所有行和列的表名.
但通过邮局收到变量无法进行预约.谁能告诉我这部分代码有什么问题?
$query = "Select * FROM :nomecardapioBD ";
$query_params = array(
':nomecardapioBD' => $_POST['nomecardapioBD']
);
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
// Finally, we can retrieve all of the found rows into an array using fetchAll
$rows = $stmt->fetchAll();